使用htaccess时,所有内部链接都会更改

时间:2015-10-19 11:40:33

标签: .htaccess

我想将我的网站网址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 / it之类的我创建了一个不存在的文件夹所以所有的内部链接都被更改了,如果我有一个post.php的链接它转到/ about / post .php

所有包含的页面也不起作用,例如css和图像

抱歉,我的英语不是很好。

1 个答案:

答案 0 :(得分:0)

我终于找到了我想要的东西,我在标题部分使用了这个元标记

`<base href="http://localhost/mysite/" />`

现在一切正常

ps:不要在webhost上使用localehost