可能重复:
htaccess rewrite 破坏了相对路径
我希望有人能帮助我。我正在尝试将我的网站设置为使用漂亮的 URL。
我目前有一些 htaccess 命令可以隐藏包含我所有 php 文件的子域文件夹以及将我的协议从 http 更改为 https 的命令,反之亦然。漂亮的网址被证明是困难的。我只想通过 htaccess 而不是 php 来完成。我设法编写了一个有效的命令,但在那之后我的 css 或 javascript 都不起作用。
# Redirect from website.com to www.website.com
RewriteCond %{HTTP_HOST} ^website.com [NC]
RewriteCond %{HTTP_HOST} !^www [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
# redirect url to www
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /defaultfolder/([^\ ]+)\ HTTP/
RewriteRule ^(.*)$ defaultfolder/error.php [L]
#this section hides the defaultfolder, tried to modify this code here to make friendly urls.
RewriteCond %{HTTP_HOST} www.website.com
RewriteCond %{REQUEST_URI} !defaultfolder/
RewriteCond %{REQUEST_URI} !images/
RewriteRule ^(.*)\/$ defaultfolder/$1\.php [L]
#https redirect
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} (/defaultfolder/)(login|securepages|pages)\.php
RewriteRule ^defaultfolder/(.*)$ https://www.website.com/$1 [R,L]
#http redirect
RewriteCond %{SERVER_PORT} 443
RewriteCond %{REQUEST_URI} (/defaultfolder/)(index|nonsecure pages)\.php
RewriteRule ^defaultfolder/(.*)$ http://www.website.com/$1 [R,L]