Home > Net >  Redirect url contains both numbers and letters with Htaccess
Redirect url contains both numbers and letters with Htaccess

Time:02-02

Im trying to Rewrite my url with this htaccess code

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{HTTPS} off
    RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
    ErrorDocument 404 mysite
    RewriteRule ^([a-z-] )$ /name.php?n=$1 [NC]
    RewriteRule ^([0-9] )$ /age.php?e=$1 [NC]

</IfModule>

when i tried open link mysite/abc or mysite/20. Both of them are working but if try this mysite/abc123 or mysite.com/a2b2c the page show error message. This page isn’t working

How can i redirect those link mysite/abc123 , mysite/a2b2c to my home page mysite with htaccess ?

Thank you!

CodePudding user response:

You may try these rules:

ErrorDocument 404 /
RewriteEngine On
RewriteBase /

RewriteCond %{HTTPS} !on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]

RewriteRule ^([a-z-] )/?$ name.php?n=$1 [L,QSA,NC]
RewriteRule ^([0-9] )/?$ age.php?e=$1 [L,QSA,NC]

ErrorDocument 404 / will forward all not found URLs to home page without changing the URL in browser. If you want to redirect those 404 URLs and want to change them to home (landing) page then use:

ErrorDocument 404 https://example.com/
  • Related