简体   繁体   中英

redirect without changing url

I always suck at .htaccess I'm trying to have a website where all requests go though index.php but i'd like the URL to be like www.sample.com/home. effectively that url would load www.sample.com/index.php?page=home

Right now I have

 RewriteRule ^/([a-z0-9-]+) /index.php?page=$1 [NC,PT,L]

Which doesnt work even though regexr test shows it should. I temporarily changed it to r=301 so i could see the redirect and noticed that www.sample.com/home is redirecting to www.sample.com/index.php?page=/index.php :(

Any thoughts?

Note I've been searching for this for a while and I can't find a solution that actually works. It's not like this was my first stop.

Change your rule to:

# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+index\.php\?page=([^\s&]+) [NC]
RewriteRule ^ /%1? [R=301,L]

RewriteRule ^([a-z0-9-]+)/?$ /index.php?page=$1 [QSA,L,NC]

Reference: Apache mod_rewrite Introduction

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM