View Full Version : PHP, Apache and Clean URLs
Dean[SAS]
12-10-2005, 08:42
I'm currently transferring my companies website from a dodgy ASP CMS to a custom PHP backend.
At the moment the sites pages are 'page.html' which the CMS dynamically creates.
We wil be moving to an apache server and i'd like to keep the page names the same so our google rankings arn't affected.
At the moment the new backend pages are accessed through www.domain.com/?page=page.html .
Is it possible to make it so /page.html blind redirects to /?page=page.html, with something like mod-rewrite?
Thanks
MrBoombastic
12-10-2005, 10:44
This in your root directory .htaccess should do what you want (I think):
RewriteEngine on
RewriteRule ^/(.*) /?page=$1
This will enable you to request a url such as:
blahblah.com/page1.html
and your request will be invisibly translated to:
blahblah.com/?page=page1.html
I've got something similar on my site, so a URL request of:
http://www.childfriendly.net/view/place/818
is actually translated to:
http://www.childfriendly.net/view.php?type=place&id=818
Hope this helps :)
Dean[SAS]
12-10-2005, 11:17
Thanks, but that doesn't seem to work. My script is index.php?page=page.html but i just get a 404
MrBoombastic
12-10-2005, 12:18
']Thanks, but that doesn't seem to work. My script is index.php?page=page.html but i just get a 404
OK, try:
RewriteRule ^/(.*) /index.php?page=$1
Dean[SAS]
12-10-2005, 14:28
:( thats not happening either.
Is there anyway I can see if the .htaccess is even working?
Dean[SAS]
13-10-2005, 14:01
After hours of hacking away, this finally works:
RewriteRule ^(.*)\.html$ index.php?pagename=$1
I had to alter some of my DB so it would work, but it's all game now :)
Thanks for your help.
Dean[SAS]
20-10-2005, 09:05
One more issue, at the moment the rewrite takes over in sub directorys too, is there any way so the rewrite only happens in the base dir and any subsequent directories i specify?
Why do I always find the answer after posting?
change this ^(.*) to this ^([^/]+)
vBulletin® v3.8.7, Copyright ©2000-2012, vBulletin Solutions, Inc.