[mod_rewrite] preventing direct access to .php files
Moderator: General Moderators
[mod_rewrite] preventing direct access to .php files
I'd like to make only 1 possible path to a certain website to prevent pagerank being divided, here is the rule which is supposed to accomplish this;
RewriteBase /
RewriteRule ^([a-zA-Z0-9]+)\.php$ $1 [L]
The problem is that this rule seems to cause an infinite loop redirecting to itself over and over again... Maybe I'm too tired right now, but I can't think of another way to get it working. Does anyone else have an idea?
RewriteBase /
RewriteRule ^([a-zA-Z0-9]+)\.php$ $1 [L]
The problem is that this rule seems to cause an infinite loop redirecting to itself over and over again... Maybe I'm too tired right now, but I can't think of another way to get it working. Does anyone else have an idea?
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
Code: Select all
RewriteRule ^(.+)?$ /index.php?p=$1 [QSA,L]Won't this also cause a loop?Everah wrote:This takes just about any URL to your site and redirects it to index.php?p=WhatWasEntered.Code: Select all
RewriteRule ^(.+)?$ /index.php?p=$1 [QSA,L]
index.php?p=WhatWasEntered
index.php?index.php?p=WhatWasEntered
index.php?index.php?index.php?p=WhatWasEntered
If not; why does my rule (RewriteRule ^([a-zA-Z0-9]+)\.php$ $1 [L] ) cause a loop?
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
Well damn, yes it does. Sorry about that. Try this one...
This takes anything that comes to your site and redirects ([R]) them to your other selected page. This will not cause infinitie loops with the R flag.
PS, I got this from the cheatsheet in the Apache, IIS, Web Servers that is listed in the Useful Resources thread.
Code: Select all
RewriteRule ^(.*)$ index.php?p=$1 [R,NC,L]PS, I got this from the cheatsheet in the Apache, IIS, Web Servers that is listed in the Useful Resources thread.
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
Right now people can use both http://www.domain.tld/page and http://www.domain.tld/page.php, I want only http://www.domain.tld/page to be available, if possible.Everah wrote:Explain this a little better. I'm not quite understanding what you mean here.nutkenz wrote:Yes, but then the user sees the .php file which is exactly what I don't want. I only want one possibility so links are always consistent...
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
http://httpd.apache.org/docs/1.3/mod/mo ... ewriteCond talks about "-f" and such.. hmmmm..