我试图隐藏.php扩展名从我的文件以及强制斜线上生成的网址。
I'm trying to hide the .php extension from my files as well as force a trailing slash on the resulting URLs.
例如:一个请求/about.php将成为/约/和请求/左右会去/约/.
Example: A request to /about.php would become /about/ and requests to /about would go to /about/.
下面重写code非常完美,当我在我的hostdomain根:
The following rewrite code worked perfectly when I was in the root of my hostdomain:
RewriteEngine On
RewriteRule ^(.*)/$ /$1.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://edit.mydomain.org/$1/ [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9} /(.*).php HTTP/ [NC]
RewriteRule .+ http://edit.mydomain.org/%1 [R=301,QSA]
不过,我需要将我的文件到该主机名称的目录。增加一个目录名的规则和具有在目录中的.htaccess本身并未在所有工作,似乎导致一个无端重定向
However, I need to move my files into a directory of this host name. Adding a directory name to the rules and having the .htaccess in the directory itself didn't work at all and seems to cause a endless redirect.
我看了看周围的StackOverflow和其他网站,并试图例子不胜枚举,并结束了与许多不同的错误,最常见的是:
I looked around StackOverflow and other websites and tried numerous examples and ended up with many different errors with the most common being:
在一切都是无止境的重定向。 除了目录主页一切是一个500错误。 about.php重定向到/左右,但没有重定向/要/和/约/显示500错误。 在一切工作,但没有一个文件名访问主页index.php文件(目录),进入无限的重定向。 事情重定向到edit.mydomain.org/home/username/public_html/mydomain.org/edit/pagename.php~~V这显然不存在。感谢您的帮助!我真的需要保留这些文件的目录虽然的.htaccess可以进入主机名root如果需要的。
Thanks for any help! I really need to keep these files in a directory although the .htaccess could go into the host name root if its needed.
这个目录将是edit.mydomain.org/dave /
The directory for this would be edit.mydomain.org/dave/
推荐答案
另存为一个的.htaccess,并把它放在戴夫目录
Save this as a .htaccess and put it in the 'dave' directory
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !..+$
RewriteCond %{REQUEST_URI} !/$
RewriteRule ^(.*)$ http://edit.mydomain.org/dave/$1/ [R=301,L]
RewriteRule ^(.*)/$ $1.php [L]
相关推荐
最新文章