我有以下工作:
removes the www section from the url if used
hides the .php section from the url
hides the /parts folder eg:(happylocation.it/parts/anotherpart/this.php into happylocation.it/anotherpart/this.php)
事实:
parts is a real folder/directory
anotherpart is a real folder/directory and has all the php files
there are no other files in <root> other then index.php
there are no files in the parts folder/directory
文件夹/目录结构:
<root>/index.php
<root>/parts/anotherpart/this.php
我跑了什么.htacces:
Options -Indexes
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.happylocation.it$ [NC]
RewriteRule ^(.*)$ https://happylocation.it/$1 [R=301,L]
RewriteCond %{THE_REQUEST} \s/parts/([^\s]+)\s [NC]
RewriteRule ^ %1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}/parts/$1 -f
RewriteRule ^(.+)$ /parts/$1 [L,QSA]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [L]
问题是,当浏览到happylocation.it/anotherpart/this时,它会在此服务器上找不到 。我希望实现的是拥有像
这样的网址happylocation.it/anotherpart/this/friendlypageID
答案 0 :(得分:1)
您应该执行此规则
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}/parts/$1 -f
RewriteRule ^(.+)$ /parts/$1 [L,QSA]
像这样。
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)/?$ /parts/$1 [L,QSA]