Need url rewriting help 2

Discuss practical ways rearrange URLs using mod_rewrite.

Postby laisfun » Wed Oct 22, 2008 12:42 am

1) You'll either need to change your site to be static pages
e.g., http://www.future-gam1ng.com/news.html
and have Mod_Rewrite direct requests from
e.g., http://www.future-gam1ng.com/?p=news
to
e.g., http://www.future-gam1ng.com/news.html

- or -

2) You'll need to change all your page links from
http://www.future-gam1ng.com/?p=news
to
http://www.future-gam1ng.com/news.html
and have Mod_Rewrite parse the new URL's
to your cgi/php script engine
( i.e, http://www.future-gam1ng.com/?p=news).

3) I just thought of another way which would be
much easier to do. You can have Mod_Rewrite
do all the redirection without changing your
links physically.

Basic example:

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^\?p=([^/]+)$ /$1.html [R=301,L]

RewriteRule ^([^/]+)\.html /?p=$1 [L]
laisfun
 
Posts: 16
Joined: Sun Aug 27, 2006 7:03 pm
Location: CA, USA

Postby Aldini » Wed Oct 22, 2008 3:44 am

there is no 301 redirect with this rewrite rules. the 301 redirect does not work
Aldini
 
Posts: 6
Joined: Thu Jun 26, 2008 1:55 am

Postby richardk » Wed Oct 22, 2008 7:33 am

Just 301 redirects
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{QUERY_STRING} ^(.*&)?p=newsitem(&.*)?$ [NC]
RewriteCond %{QUERY_STRING} ^(.*&)?newsid=([0-9]+)(&.*)?$ [NC]
RewriteRule ^$ /newsitem/%2.html? [R=301,L]

RewriteCond %{QUERY_STRING} ^(.*&)?p=profile(&.*)?$ [NC]
RewriteCond %{QUERY_STRING} ^(.*&)?userid=([0-9]+)(&.*)?$ [NC]
RewriteRule ^$ /profile/%2.html? [R=301,L]

RewriteCond %{QUERY_STRING} ^(.*&)?p=([^&]+)(&.*)?$ [NC]
RewriteRule ^$ /%2.html? [R=301,L]


With rewrites too
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{QUERY_STRING} ^(.*&)?p=newsitem(&.*)?$ [NC]
RewriteCond %{QUERY_STRING} ^(.*&)?newsid=([0-9]+)(&.*)?$ [NC]
RewriteRule ^$ /newsitem/%2.html? [R=301,L]

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{QUERY_STRING} ^(.*&)?p=profile(&.*)?$ [NC]
RewriteCond %{QUERY_STRING} ^(.*&)?userid=([0-9]+)(&.*)?$ [NC]
RewriteRule ^$ /profile/%2.html? [R=301,L]

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{QUERY_STRING} ^(.*&)?p=([^&]+)(&.*)?$ [NC]
RewriteRule ^$ /%2.html? [R=301,L]

RewriteRule ^newsitem/([0-9]+)\.html$ /?p=newsitem&newsid=$1 [QSA,L]
RewriteRule ^profile/([0-9]+)\.html$  /?p=profile&userid=$1  [QSA,L]
RewriteRule ^([^/]+)\.html$           /?p=$1                 [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby laisfun » Wed Oct 22, 2008 11:20 am

I'm impressed Richard, great work!!!
laisfun
 
Posts: 16
Joined: Sun Aug 27, 2006 7:03 pm
Location: CA, USA

Postby Aldini » Wed Oct 22, 2008 2:30 pm

Thank you, richard K. You are the best!
Aldini
 
Posts: 6
Joined: Thu Jun 26, 2008 1:55 am


Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: No registered users and 8 guests

cron