我想将我的网站urls从www.mysite.com/about.php更改为www.mysite.com/about/
我在htaccess文件中使用了以下代码
# Apache Rewrite Rules
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
# Add trailing slash to url
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/|#(.*))$
RewriteRule ^(.*)$ $1/ [R=301,L]
# Remove .php-extension from url
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^([^\.]+)/$ $1.php
# End of Apache Rewrite Rules
</IfModule>我也试过这个
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/$ $1.php
RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]它可以工作,但所有页面内容都在/about/中,就像我创建了一个不存在的文件夹,所以所有内部链接都被更改了,如果我有一个指向post.php的链接,它会转到/about/post.php
所有包含的页面都不能正常工作,例如css和图像
对不起,我的英语不太好。
发布于 2015-10-20 00:46:23
我最终找到了我想要的东西,我在header部分使用了这个meta标记
`<base href="http://localhost/mysite/" />`现在一切都正常了
ps:不要在webhost上使用localehost
https://stackoverflow.com/questions/33213453
复制相似问题