Let say I have an old URL http://abc.com/x.php?a=xyz&b=jkl I need to redirect all the request to page x.php either having query string or not to http://xyz.com/x/
Below is the .htaccess file which is present in root of http://xyz.com
# Turn on URL rewriting
RewriteEngine On
RewriteBase /
# Protect application and system files from being viewed
RewriteRule ^(application|modules|system) - [F,L]
# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $0 !=server-status
# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php/$0 [PT,L]
In the htaccess file in your document root, add these rules:
RewriteEngine On
RewriteRule ^/?x.php$ /x/? [L,R=302]
Note that if you have rules to rewrite /x/
back to /x.php
, these 2 rules will conflict and cause an internal loop. You can prevent the loop by including a:
RewriteCond %{ENV:REDIRECT_STATUS} !200
right above the above RewriteRule
.
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.