[英].htaccess allow extension, allow no extension, and allow trailing slash
I am having trouble coding my htaccess file to do what I need it to do.我在编写 htaccess 文件以执行我需要它执行的操作时遇到问题。
Here is what I have so far:这是我到目前为止所拥有的:
RewriteOptions inherit
ErrorDocument 404 http://www.tempsite.com/400.php
ErrorDocument 500 http://www.tempsite.com/500.php
RewriteEngine On
RewriteRule ^index/?$ index.php [NC]
RewriteRule ^pricing/?$ pricing.php [NC]
RewriteRule ^support/?$ support.php [NC]
RewriteRule ^about/?$ about.php [NC]
RewriteRule ^learning/?$ learning.php [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ $1.php [L]
So from my testing and my knowledge what this does is:因此,根据我的测试和我的知识,它的作用是:
This does what im wanting HOWEVER I don't want to have to add each page like: RewriteRule ^index/?$ index.php [NC]
every time I create a new page so how do I write a RewriteRule
that does the same thing (allows the page with a slash and without) but for all domain pages?这就是我想要的但是我不想添加每个页面,例如:
RewriteRule ^index/?$ index.php [NC]
每次我创建一个新页面时,我该如何编写一个RewriteRule
来做同样的事情(允许页面带斜线和不带)但对于所有域页面?
You can use:您可以使用:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.+?)/?$ $1.php [L]
Instead of all lines from RewriteRule ^index/?$ index.php
...而不是
RewriteRule ^index/?$ index.php
的所有行...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.