Home > other >  How do i redirect subdirectory to URL parameter in .htaccess
How do i redirect subdirectory to URL parameter in .htaccess

Time:06-29

I want to redirect a subdirectory to a URL-parameter in the .htaccess

Like this:

domain.com/search/123 -> domain.com/searchresult?search=123

How is this possible in .htaccess

CodePudding user response:

Have you checked mod_rewrite?

There even is an "Rewrite query string" example:

This solution shows the reverse of the previous ones, copying path components (perhaps PATH_INFO) from the URL into the query string.

# The desired URL might be /products/kitchen-sink, and the script expects
# /path?products=kitchen-sink.
RewriteRule "^/?path/([^/] )/([^/] )" "/path?$1=$2" [PT]

-- https://httpd.apache.org/docs/current/rewrite/remapping.html#rewrite-query

CodePudding user response:

Should be possible with

RewriteEngine On
RewriteRule ^/(.*)$ searchresult?$1=$2 [R=301,L]
  • Related