2017-09-16 293 views
2

对我的问题可能有一个非常简单的答案,但经过几个小时的浏览,我仍然没有找到解决方案,所以非常感谢您的帮助。也许我应该提到,我在Bluehost中使用了一个子域(同一个帐户上有多个域)。Htaccess Rewrite漂亮URL

我想改写:www.example.com/myfolderwww.example.com/index.php?s=myfolder

RewriteEngine On 
RewriteBase/
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^([^/]+)/?$ /index.php?s=$1 [L] 
  • example.com/abcd - >工作
  • example.com/abcd/ - >的作品,但破坏了我的图片的URL
  • example.com/abcd/index.php - >不起作用(重定向我 主页)

非常感谢您的帮助。 罗兰

回答

0

要重写索引,使用:

RewriteEngine On 
RewriteBase/
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^(.+)/?$ /index.php?s=$1 [L] 

而且对CSS,脚本或图片,使用绝对s链接(以/http://...开头)或在html头文件中添加<base href="/">

+1

非常感谢!有用! –