我有以下代码
RewriteEngine On
RewriteBase /
## hide .php extension snippet
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1/ [R,L]
# add a trailing slash
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !/$
RewriteRule . %{REQUEST_URI}/ [L,R=301]
# To internally forward /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [L]
我想要做的是想删除.PHP扩展并在URL中添加前导斜杠,该代码删除.php扩展名并添加前导斜杠但是它会抛出以下错误
Not Found
The requested URL /Parties.php was not found on this server.
我的网址在
之下http://localhost/legalHQWithNewAddressTable/legalHQ/public/admin/Parties/
我该怎么做才能让它发挥作用。
任何想法?
答案 0 :(得分:1)
您可以使用以下两种修复中的任何一种:
http://
或斜杠/legalHQWithNewAddressTable/legalHQ/public/admin/
开头。<base href="/legalHQWithNewAddressTable/legalHQ/public/admin/" />
,以便从该网址解析每个相对网址,而不是当前网址。答案 1 :(得分:1)
首先需要添加以下内容
RewriteBase /legalHQWithNewAddressTable/legalHQ/public/admin
然后在html页面的头部分添加以下标记
<base href="/legalHQWithNewAddressTable/legalHQ/public/admin/" />
尝试并告诉我是否有效