How to keep original URL in addressbar after Rewri

2019-07-17 05:43发布

This is my .htaccess file.

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]

The rewrite rule

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

Redirects the url www.mydomain.co.uk/listen to www.mydomain.co.uk/console

This redirect works fine, but I want the visable url in the address bar to read...

www.mydomain.co.uk/listen

Any help greatly appreciated. Thanks

1条回答
唯我独甜
2楼-- · 2019-07-17 06:22

Have it this way:

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]

Test it after clearing your browser cache.

查看更多
登录 后发表回答