adnen manssouri
adnen manssouri

Reputation: 51

Rewrite URL and redirect base url using htacesss

i'm new at htaccess rewrite rule and regex expression i'want to rewrite my base url -> /service/authentication/?step=1 to -> /service/new/auth/1

step= is a parameter from 1 to 5

so my rule is :

RewriteRule ^new/auth/([^/.]+)?$ /service/index.php/authentication/?step=$1 [L]
RewriteRule ^new/auth/([^/.]+)?/$ /service/index.php/authentication/?step=$1 [L]

so when I access /service/new/auth/8 in the url it work very good

so after that i'created a new rules to redirect the base url to the rewriten url

my rule is :

RewriteRule ^authentication/$ /service/new/auth/$1 [L,R]

the base url now redirect to /service/new/auth/?step=1

the problem it must redirect to /service/new/auth/1 without showing step=1 and the ? must be the id

i'think i have a problem in my regax

thanks for all helps

Upvotes: 1

Views: 251

Answers (1)

RavinderSingh13
RavinderSingh13

Reputation: 133538

With your shown samples, please try following htaccess Rules. Make sure to place these rules before your rewrite rules(which I assume already present in your file).

Make sure to clear your browser cache before testing your URLs.

RewriteEngine ON
##Rules for external redirect goes from here....
RewriteCond %{THE_REQUEST} \s/service/authentication\?step=(\d+)\s
RewriteRule ^ /service/new/auth/%1? [R=301,L]
##rest of your rules for internal redirect/rewrite goes from here..

Upvotes: 1

Related Questions