0

One of my website's old URL structures is like this:

 https://example.com/login.php or, https://example.com/login.php?redirect=https://example.com or, https://example.com/register.php 

after rebuilding the URLs, the URLs look like this:

 https://example.com/login or, https://example.com/login?redirect=https://example.com or, https://example.com/register 

Now when the user/visitor uses the old URL https://example.com/login.php, I want to redirect to the https://example.com/login page. How can I do it?

FYI, currently, my .htaccess file has the following content:

AddDefaultCharset UTF-8 ErrorDocument 404 /error-404/ ## Options +FollowSymlinks -MultiViews RewriteEngine on RewriteBase / ## Allow a few SEO Files direct access. RewriteRule ^robots.txt?$ robots.txt [L] RewriteRule ^ads.txt?$ ads.txt [L] RewriteRule ^sellers.json?$ sellers.json [L] ## Avoid rewriting rules for the admin section RewriteRule ^(admin|resources)($|/) - [L] ## Set Ajax Request File RewriteRule ^kahuk-ajax.php?$ kahuk-ajax.php? [L,QSA] ## Set controller with id RewriteRule ^([^/]+)/([0-9]+)/?$ index.php?con=$1&id=$2 [L,QSA] ## Set controller with slug RewriteRule ^([^/]+)/([^/]+)/?$ index.php?con=$1&slug=$2 [L,QSA] ## For paging RewriteRule ^([^/]+)/page/([0-9]+)/?$ index.php?con=$1&page=$2 [L,QSA] RewriteRule ^([^/]+)/([^/]+)/page/([0-9]+)/?$ index.php?con=$1&slug=$2&page=$3 [L,QSA] ## Set controller for only one parameter RewriteRule ^page/([^/]+)/?$ index.php?con=page&slug=$1 [L,QSA] RewriteRule ^([^/]+)/?$ index.php?con=$1 [L,QSA] ## Set home page RewriteRule ^/?$ index.php?con=home [L] 

1 Answer 1

1

You can insert this rule just below RewriteBase / line to remove .php extension:

# To externally redirect /afile.php to /afile RewriteCond %{THE_REQUEST} \s/+(.+?)\.php[\s?] [NC] RewriteRule !^admin/ /%1 [R=301,NE,L,NC] 
Sign up to request clarification or add additional context in comments.

8 Comments

Seems it is good, but it is also overriding extension from this URL https://example.com/admin/admin_attention?hello=world. I don't want to redirect when the file is in /admin.
ok try my updated rule now
No luck. Still redirecting from https://example.com/admin/admin_attention.php?hello=world to https://example.com/admin/admin_attention?hello=world.
FYI, it does not redirect the https://example.com/admin/admin_links.php to https://example.com/admin/admin_links. which is good.
my bad, I guess your solution is working. I need to test it more after clearing the cache. Anyway, THANK YOU very much.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.