Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2005-12-02 18:56:43

1beb
Plugin Author
From: Canada, Ontario, Toronto
Registered: 2004-11-22
Posts: 169
Website

help with a rewrite!

Hi All,

is there any way to rewrite this url:

http://sub.domain.com/?id=100&something=200

to:

http://sub.domain.com/photo/100/200

Is that possible?

Although, idealy, I would rather have it like this:

http://sub.domain.com/photo/article-title/200

but I think that requires to much work.

Any thoughts?

Offline

#2 2005-12-02 19:18:26

edburdo
Member
Registered: 2004-09-20
Posts: 79
Website

Re: help with a rewrite!

yes, your first example is doable. How? you’ll have to get someone else to show you the code. I do know it can be done, since I had someone write something similar for me once.

the second option could be done if you wanted to use PHP to handle the redirects (instead of the .htaccess file). You would need to pull the article-title from the db, then redirect to that page.


Eric

Offline

#3 2005-12-02 20:57:58

1beb
Plugin Author
From: Canada, Ontario, Toronto
Registered: 2004-11-22
Posts: 169
Website

Re: help with a rewrite!

Well then, I guess I’m looking for a mod-rewrite master to help me out a little!

Offline

#4 2005-12-02 21:12:10

edburdo
Member
Registered: 2004-09-20
Posts: 79
Website

Re: help with a rewrite!

I found a lot of the mod rewrite sites use what your looking at as an example. So you might be able to find some samples via Google and then make them fit your particulars.


Eric

Offline

#5 2005-12-02 23:13:33

1beb
Plugin Author
From: Canada, Ontario, Toronto
Registered: 2004-11-22
Posts: 169
Website

Re: help with a rewrite!

Thanks! I wouldn’t have come to the forums if I didn’t already try that. ;)

Offline

#6 2005-12-02 23:28:50

Sencer
Archived Developer
From: cgn, de
Registered: 2004-03-23
Posts: 1,803
Website

Re: help with a rewrite!

http://sub.domain.com/?id=100&something=200
to:
http://sub.domain.com/photo/100/200

No guarantuee, untested. Idally test this locally first. ;)

RewriteCond %{QUERY_STRING} id=([0-9]+).*something=([0-9]+)
RewriteRule .* /photo/%1/%2? [R=301,L]

(note: The question-mark at the end is necessary to prevent an endless loop: it “empties” the query string).

Offline

#7 2005-12-02 23:41:35

1beb
Plugin Author
From: Canada, Ontario, Toronto
Registered: 2004-11-22
Posts: 169
Website

Re: help with a rewrite!

Nah that didn’t seem to work. Although something interesting to note is that…

sub.domain.com/photo/?id=100&imagenum=200 now redirects to /photo/100/200

Here’s the whole .htaccess file if it helps…

#DirectoryIndex index.php index.html
#Options +FollowSymLinks
#RewriteBase /relative/web/path/

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^diana.bertelsen.ca$ [NC]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.+) – [PT,L]

RewriteRule ^(.*) /index.php
RewriteCond %{QUERY_STRING} id=([0-9]+).*imagenum=([0-9]+)
RewriteRule .* /photo/%1/%2? [R=301,L]
</IfModule>

#php_value register_globals 0

Last edited by 1beb (2005-12-02 23:42:14)

Offline

#8 2005-12-03 00:16:14

1beb
Plugin Author
From: Canada, Ontario, Toronto
Registered: 2004-11-22
Posts: 169
Website

Re: help with a rewrite!

Gah, all that I can get to happen is “404 not found!”

Offline

#9 2005-12-03 14:54:21

edburdo
Member
Registered: 2004-09-20
Posts: 79
Website

Re: help with a rewrite!

Is it generating the URLs correctly, and something else is breaking, or is it generating the wrong URL?


Eric

Offline

#10 2005-12-03 21:46:03

1beb
Plugin Author
From: Canada, Ontario, Toronto
Registered: 2004-11-22
Posts: 169
Website

Re: help with a rewrite!

It generates the correct URL, but txp says “no, thank you.”

Offline

Board footer

Powered by FluxBB