I have the following urls:
http://superawesomedomain.com/recently-created.html
http://superawesomedomain.com/recently-created.html
http://superawesomedomain.com/articles/recently-created.html
http://superawesomedomain.com/surveys/0-6-months.html
And I want to redirect them to the following URL:
http://superawesomedomain.com/search_redirect?q=recently-created
http://superawesomedomain.com/search_redirect?q=recently-created
http://superawesomedomain.com/search_redirect?q=recently-created
http://superawesomedomain.com/search_redirect?q=0-6-months
I have trouble getting the filename (without the extension) and append it to the url that I want.
I have to do the redirect with .htaccess
I'll very thankful for your help.
Doesn't this work?
/recently-created.html /search_redirect?q=recently-created
/recently-created.html /search_redirect?q=recently-created
/articles/recently-created.html /search_redirect?q=recently-created
/surveys/0-6-months.html /search_redirect?q=0-6-months
You should only need to use http://superawesomedomain.com if on another server.
You can use the following redirect in /root/.htaccess :
RedirectMatch 302 ^/(?:[^/.]*/)?([^.]+)\.html$ http://domain.com/search_redirect/?q=$1
This will redirect
/foo/bar.html
or
/bar.html
to
/search_redirect/?q=bar
If you want to make the redirect Permanent ,change the statust code 302 to 301 .
Refrence : - https://httpd.apache.org/docs/current/mod/mod_alias.html