我有以下代码
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.
我的URL在
下面http://localhost/legalHQWithNewAddressTable/legalHQ/public/admin/Parties/
我该怎么做才能使它工作呢?
任何想法?
您可以使用以下两种方法中的任何一种:
- 在css, js, images文件中使用绝对路径,而不是相对路径。这意味着您必须确保这些文件的路径以
http://
或斜杠/legalHQWithNewAddressTable/legalHQ/public/admin/
开头。 - 你可以尝试在你的页面的HTML标题中添加:
<base href="/legalHQWithNewAddressTable/legalHQ/public/admin/" />
,以便每个相对URL都从该URL而不是当前URL解析。
首先您需要添加以下
RewriteBase /legalHQWithNewAddressTable/legalHQ/public/admin
,然后在HTML页面
的标题部分添加以下标记<base href="/legalHQWithNewAddressTable/legalHQ/public/admin/" />
试一下,然后告诉我是否有效