【发布时间】:2015-01-18 10:19:14
【问题描述】:
我进行了一些重写,会将文件名更改为 url 结构。
http://example.com/landing-myfile.html 将转换为http://example.com/landing/myfile/
我正在尝试设置默认页面,保留 url,然后重新处理规则。
所以如果用户输入http://example.com/asdfasdfasdf
它将重定向到http://example.com/landing-mydefault.html
但我希望它显示为http://example.com/landing/mydefault/
我已经对所有漂亮的 URL 进行了重写,并且我缺少重定向到默认页面的文件夹/文件。但是我需要继续重写所有其他规则。
这是我目前所拥有的。
RewriteEngine On
RewriteBase /
#redirects bad requests to a default.
#works but leavings landing-mydefault.html in the address bar.
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /landing-mydefault.html [R,L]
#process the pages and converts them to pretty urls.
#everything below works as it should.
RewriteCond %{THE_REQUEST} landing-([^.]+)\.html\s [NC]
RewriteRule ^ /landing/%1/ [R=302,L,NE]
RewriteCond %{THE_REQUEST} landing-([^.]+)\.html\?v=([^\s&]+) [NC]
RewriteRule ^ /landing/%1/%2? [R=302,L,NE]
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
RewriteRule ^landing/([^/]+)/?$ /landing-$1.html [L]
RewriteRule ^landing/([^/]+)/([^/]+)/?$ /landing-$1.html?v=$2 [L,QSA]
【问题讨论】:
标签: regex apache .htaccess mod-rewrite redirect