2013-10-26 117 views
1

所以我试图把我的网站从这个:如何从URL中删除子目录?

http://profe5.com/Profe5-Web/public_html/login.html

要这样:

http://profe5.com/login

我一直在努力做的这个,但每当我运行它,我得到404错误!

这是我的htaccess:

DirectoryIndex Profe5-Web 
    RewriteEngine On 
    RewriteBase/
    RewriteCond %{HTTP_HOST} !^profe5\.com$ [NC] 
    RewriteRule ^(.*)$ http://profe5.com/$1 [R=301,L] 
    RewriteCond %{SCRIPT_FILENAME} !-d 
    RewriteRule ^([^\.]+)$ $1.html [R=301,L] 
    RewriteRule ^Profe5-Web/public_html/(.*)$ $1 [R=301,L] 

这将是如此真棒,如果你们能帮助我! 非常感谢!

回答

1

这应该是你的完整的.htaccess:

DirectoryIndex Profe5-Web 
RewriteEngine On 
RewriteBase/

RewriteCond %{HTTP_HOST} !^profe5\.com$ [NC] 
RewriteRule ^(.*)$ http://profe5.com/$1 [R=301,L] 

# external redirect from actual URL to pretty one 
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+Profe5-Web/public_html/([^.]+)\.html [NC] 
RewriteRule^%1? [R=301,L] 

# internal forward from pretty URL to actual one 
RewriteCond %{SCRIPT_FILENAME} !-f 
RewriteCond %{SCRIPT_FILENAME} !-d 
RewriteRule ^([^/.]+)/?$ Profe5-Web/public_html/$1.html [L,QSA] 
+0

这个工程差不多了吧,这个唯一的问题是,现在的链接的文件不会加载。例如没有找到css文件和JS文件! –

+0

对于css,js不加载的问题,解决方法很简单,只需在你的css,js,images文件中使用绝对路径而不是相对路径。这意味着你必须确保这些文件的路径以'http://'或斜杠'/'开始。 – anubhava

0

你可能会考虑通过虚拟主机来做到这一点;与您的托管公司检查有关设置它

0

如果你想/login映射到Profe5-Web/public_html/login.html - 试试这个:

RewriteRule ^([^.]+)$ Profe5-Web/public_html/$1.html [R=301,L] 

你已经拥有的重写规则,RewriteRule ^([^\.]+)$ $1.html [R=301,L]将映射到/login/login.html,这似乎并不做你需要的东西。