简体   繁体   中英

htaccess remove ? from the url and redirect

I've some dynamic urls. If I took a url with a query parameter, it leads to 404 page. So I would like to do a redirection using htaccess. I tried many possible solutions, and none of them worked.

Url structure will be /jobs/job-***.html?something and which I need to redirect to /jobs/job-***.html

I tried something like this, but returned 500 error;

RewriteRule ^jobs/job-([0-9]+).html?$ jobs/job-$1 [NC, L]

Please help to solve this problem.

You may use this rule:

RewriteCond %{QUERY_STRING} .
RewriteRule ^jobs/job-(\d+\.html?)$ %{REQUEST_URI}? [NC,L,R=301]

? after $1 in target will remove any query string.

You may use the following regex:

^\\/jobs\\/job-(\\d+)\\.html\\?\\S*$

(This essentially captures the job number)

and then replace it with:

/jobs-$1.html

Demo

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM