.htaccess htaccessurl修饰:保留非html/php路径

.htaccess htaccessurl修饰:保留非html/php路径,.htaccess,mod-rewrite,.htaccess,Mod Rewrite,我试图将所有的.html和.php文件显示为目录路径,例如 www.domain.com/path/page.html将显示为www.domain.com/path/page/ 我微弱的尝试,基于几个小时的搜索和阅读-编辑:做了一些改变,改变了行为 # Rewrite to pretty URL RewriteCond %{REQUEST_FILENAME} -f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} !.*

我试图将所有的.html和.php文件显示为目录路径,例如

www.domain.com/path/page.html将显示为www.domain.com/path/page/

我微弱的尝试,基于几个小时的搜索和阅读-编辑:做了一些改变,改变了行为

# Rewrite to pretty URL
RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !.*\.(ico|gif|jpg|jpeg|png|js|css)
RewriteCond %{REQUEST_URI} .*\.(html|php)
RewriteRule ^(\S+\/)*(\S+)\.html$ $1$2/ 
第一条规则现在重定向到,这是所需的行为。 第二条规则启用后,将导致500响应

# Redirect to actual file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !.*\.(ico|gif|jpg|jpeg|png|js|css)
RewriteRule ^(\S+\/)*(\S+)\/$ $1$2.html
第一条规则尝试匹配整个路径,然后匹配文件,将其重写为目录格式

第二种方法尝试读取目录格式并将其发送到相应的文件。我要死了。两者都不起作用,我只是迷路了

编辑:当我直接导航到文件夹格式时,它会做一些事情,但也会将/index/添加到对css、js和img资源的所有请求中,因此它看起来是错误的。它还将/index/添加到页面上的所有链接,这将导致404

编辑:这是我的完整htaccess文件供参考。没什么特别的

AddType application/x-httpd-php .html .htm

# Prevent Directoy listing 
Options -Indexes

# Prevent Direct Access to files
<FilesMatch "(?i)((\.tpl|\.ini|\.log|(?<!robots)\.txt))">
 Order deny,allow
 Deny from all
</FilesMatch>

# SEO URL Settings
RewriteEngine On
RewriteBase /

# Redirects requests for my images to a bad image
RewriteCond %{HTTP_REFERER} !^https?://(.+\.)?domain\.com/ [NC]
RewriteCond %{HTTP_REFERER} !^$
RewriteRule .*\.(jpe?g|gif|bmp|png|jpg)$ /image/catalog/theft_prevention.jpe [L]

# Redirects non-www to www
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

# serve custom error pages
ErrorDocument 400 /error-400.html
ErrorDocument 401 /error-401.html
ErrorDocument 403 /error-403.html
ErrorDocument 404 /error-404.html
ErrorDocument 410 /error-410.html
ErrorDocument 500 /error-500.html

# Rewrite to pretty URL
RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !.*\.(ico|gif|jpg|jpeg|png|js|css)
RewriteCond %{REQUEST_URI} .*\.(html|php)
RewriteRule ^(\S+\/)*(\S+)\.html$ $1$2/ [R=301, L]

# Redirect to actual file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !.*\.(ico|gif|jpg|jpeg|png|js|css)
RewriteRule ^(\S+\/)*(\S+)\/$ $1$2.html [R=301, L]
AddType应用程序/x-httpd-php.html.htm
#防止Directoy上市
选项-索引
#阻止直接访问文件
命令拒绝,允许
全盘否定
#搜索引擎优化URL设置
重新启动发动机
重写基/
#将对我的图像的请求重定向到错误图像
重写cond%{HTTP_REFERER}^https?:/(.+\)?域\.com/[NC]
重写cond%{HTTP_REFERER}^$
重写规则。*\(jpe?g | gif | bmp | png | jpg)$/image/catalog/防盗.jpe[L]
#将非www重定向到www
重写cond%{HTTP_HOST}^$
重写cond%{HTTP_HOST}^www\。[北卡罗来纳州]
在上重写cond%{HTTPS}s^|
重写规则^http%1://www.%{http_HOST}%{REQUEST_URI}[R=301,L]
#提供自定义错误页面
ErrorDocument 400/error-400.html
ErrorDocument 401/error-401.html
ErrorDocument 403/error-403.html
ErrorDocument 404/error-404.html
ErrorDocument 410/error-410.html
ErrorDocument 500/error-500.html
#重写到漂亮的URL
RewriteCond%{REQUEST_FILENAME}-f
重写cond%{REQUEST_FILENAME}-D
重写条件%{REQUEST\u URI}!。*\。(ico | gif | jpg | jpeg | png | js | css)
重写cond%{REQUEST_URI}.*\(html|php)
重写规则^(\S+\/)*(\S+\.html$$1$2/[R=301,L]
#重定向到实际文件
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写条件%{REQUEST\u URI}!。*\。(ico | gif | jpg | jpeg | png | js | css)
重写规则^(\S+\/)*(\S+\/$$1$2.html[R=301,L]

第一条规则中的正则表达式在我看来是正确的()。什么不起作用?您确定您的应用程序可以处理路径吗?我使用的是一个简单的HTML模板。第二条规则用于处理路径。我实际上使用了regex101来测试这两个规则。什么不起作用?您确定您的应用程序可以处理路径吗?我使用的是一个简单的HTML模板。第二条规则用于处理路径。我实际上使用了regex101来测试这两个规则。