如何在RewriteRule之后将原始URL保留在地址栏中

时间:2015-08-20 09:30:30

标签: .htaccess url mod-rewrite url-redirection http-redirect

这是我的.htaccess文件。

Options +FollowSymLinks

<IfModule mod_security.c>
SecFilterEngine Off
SecFilterScanPOST Off
</IfModule>

RewriteEngine on

RewriteRule ^index.html             /? [R=301,L]
RewriteRule ^listen/$               /console [R=301,L]


# 301 Redirect all requests that don't contain a dot or trailing slash to
# include a trailing slash
RewriteCond %{REQUEST_URI} !/$
RewriteCond %{REQUEST_URI} !\.
RewriteRule ^(.*) %{REQUEST_URI}/ [R=301,L]

# Rewrites urls in the form of /parent/child/
# but only rewrites if the requested URL is not a file or directory
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?page=$1 [QSA]

重写规则

RewriteRule ^listen/$               /console [R=301,L]

将网址www.mydomain.co.uk/listen重定向到www.mydomain.co.uk/console

此重定向工作正常,但我希望地址栏中的可见网址读取...

www.mydomain.co.uk/listen

任何帮助非常感谢。感谢

1 个答案:

答案 0 :(得分:1)

这样做:

Options +FollowSymLinks
RewriteEngine on

# 301 Redirect all requests that don't contain a dot or trailing slash to
# include a trailing slash
RewriteCond %{REQUEST_URI} !/$
RewriteCond %{REQUEST_URI} !\.
RewriteRule ^(.*) %{REQUEST_URI}/ [R=301,L]

RewriteCond %{THE_REQUEST} /index\.html [NC]
RewriteRule ^index\.html$ /? [R=301,L,NC]

RewriteRule ^listen/$ /console/ [NC,L]

# Rewrites urls in the form of /parent/child/
# but only rewrites if the requested URL is not a file or directory
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?page=$1 [L,QSA]

清除浏览器缓存后进行测试。