Log in

View Full Version : mod_rewrite issue



Klydo
18-05-2008, 05:08 PM
The problem is that I've set it up so if you go to http://www.mysite.com/ it redirects to http://mysite.com/. As I want all the domain occurrences in Google to be the same rather than split between the two. Which was easy in itself but I am using SEO urls which include /go/pagename and if you go to say www.mysite.com/go/pagename (http://www.mysite.com/go/pagename) it redirects to http://mysite.com/pagename.php instead of http://mysite.com/go/pagename and wondering how to get this to work. Here's what I have.

I'm not a mod_rewrite expert so this may be simple or not but does anyone know how to correct it? Here's my code for it;


RewriteEngine on

RewriteRule ^go/logout/?$ process.php [L]
RewriteRule ^go/([A-Za-z0-9-]+)/?$ $1.php [L]
RewriteRule ^go/dashboard/([A-Za-z0-9-]+)/?$ dashboard.php?p=$1 [L]
RewriteRule ^([A-Za-z0-9-]+)/?$ profile.php?user=$1 [L]

RewriteCond %{HTTP_HOST} ^www.mysite.com [NC]
RewriteRule ^(.*)$ http://mysite.com/$1 [L,R=301]

Protege
18-05-2008, 06:20 PM
Could use a PHP/Javascript to do it but here


Options +FollowSymLinks

RewriteEngine On
RewriteBase /

Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\.jamesrozee\.com$ [NC]
RewriteRule ^(.*)$ http://www.jamesrozee.com/$1 [R=301,L]


http://www.askapache.com/htaccess/mod_rewrite-tips-and-tricks.html

Hypertext
18-05-2008, 06:36 PM
Try:


RewriteEngine on

RewriteRule ^go/logout/?$ process.php [L]
RewriteRule ^go/([A-Za-z0-9-]+)/?$ $1.php [L]
RewriteRule ^go/dashboard/([A-Za-z0-9-]+)/?$ dashboard.php?p=$1 [L]
RewriteRule ^([A-Za-z0-9-]+)/?$ profile.php?user=$1 [L]

RewriteCond %{HTTP_HOST} !^www.mysite.com$ [NC]
RewriteRule ^(.*)$ http://mysite.com/$1 [L,R=301]

Excellent
18-05-2008, 07:55 PM
I'm pretty sure if you added:
Options +FollowSymLinks to the top it may work as you don't need the www then. I may be wrong.

Want to hide these adverts? Register an account for free!