anulik anulik - 1 month ago 8
PHP Question

.htaccess is not redirecting from old url to new url 3

I am new in

. I have read the documentation, but couldn't make the redirect rule work.

I want
for following


I have tried out this

RewriteRule ^(.*)/[0-9]/(.*)$ ^(.*)/(.*)/$ [R=301,L]

Also how can u get the subdomain and put it to the front of all links, like this


but no result.


Rewrite this is simple:

Your rewrite rule RewriteRule ^(.*)/[0-9]/(.*)$ ^(.*)/(.*)/$ [R=301,L] is too global for the urls. Second of all you just say [0-9] with means only one digit.

RewriteRule ^([^/]+)/[0-9]+/([^.]+)\.htm$ /$1/$2 [R=301,L]

Try this one ;)

Edit (for second question):

Sure ;) There you have to work with RewriteCond.

RewriteCond %{HTTP_HOST}%{REQUEST_URI} ^([^\.]+)\.mywebsite\.com/([^/]+)/[0-9]+/([^.]+)\.htm
RewriteRule ^.*$ [R=301,L]

For explanation, the %1-3 can be used from the previous match to be used in the RewriteRule Statement. This should work for every subdomain and only for subdomains. If you want a specific subdomain you can adjust the first line to ^(sidney|othersubdomain|anothersubdomain)\.mywebsite\.com....