0

i want to ask why my .htaccess in root folder does not work well.

.htaccess

RewriteEngine On 
RewriteRule ^([a-zA-Z0-9]+)(/[a-zA-Z0-9/]+)?$ /$1\.php$2 [L]

RewriteCond %{THE_REQUEST} ^GET\s/*pages/.*\.php [NC] 
RewriteRule ^([a-zA-Z0-9]+)(/[a-zA-Z0-9/]+)?$ /$1\.php$2 [L]

RewriteCond %{THE_REQUEST} ^GET\s/*debates/.*\.php [NC]
RewriteRule ^([a-zA-Z0-9]+)(/[a-zA-Z0-9/]+)?$ /$1\.php$2 [L]

Links in the / (main folder) are with working .php hidding, but in the subfolders like /pages/ and /debates/ the system does not recognize rewrite rule. I want to hide .php in both directories like they are hidden in the main folder.

I FIND THE SOLUTION!

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+)$ $1.php [L,QSA]
4

1 回答 1

0

看起来这些规则都是错误的,他们不会做任何事情:

RewriteCond %{THE_REQUEST} ^GET\s/*pages/.*\.php [NC] 
RewriteRule ^([a-zA-Z0-9]+)(/[a-zA-Z0-9/]+)?$ /$1\.php$2 [L]

RewriteCond %{THE_REQUEST} ^GET\s/*debates/.*\.php [NC]
RewriteRule ^([a-zA-Z0-9]+)(/[a-zA-Z0-9/]+)?$ /$1\.php$2 [L]

您可以将您的 htaccess 更改为:

RewriteEngine On 
RewriteRule ^pages/([a-zA-Z0-9]+)(/[a-zA-Z0-9/]+)?$ /pages/$1\.php$2 [L]
RewriteRule ^debates/([a-zA-Z0-9]+)(/[a-zA-Z0-9/]+)?$ /debates/$1\.php$2 [L]
RewriteRule ^([a-zA-Z0-9]+)(/[a-zA-Z0-9/]+)?$ /$1\.php$2 [L]
于 2012-09-24T23:58:31.110 回答