The site I am trying to work on is http://northidahocvma.org/2GD/index.php?page=1
So suppose I have URLs with query string parameters like these:
/index.php?page=1
Using mod_rewrite, how can I redirect them to URLs like these?
/page/1 or /1/
I was given this code but still cant quite figure it out
RewriteEngine On
RewriteCond %{THE_REQUEST} \s/+index\.php\?page=([^\s&]+) [NC]
RewriteRule ^ /page/%1? [R=302,L]
RewriteRule ^page/([^/.]+)/?$ /index.php?page=$1 [L,QSA,NC]
Put this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteCond %{THE_REQUEST} \s/+index\.php\?page=([^\s&]+) [NC]
RewriteRule ^ /page/%1? [R=302,L]
RewriteRule ^page/([^/.]+)/?$ /index.php?page=$1 [L,QSA,NC]
Related
I think that this is rather simple, but I just can't wrap my head around it.
I have a domain like https://www.example.com
I want to rewrite it to https://example.com
That works. But I am also rewriting other urls like https://www.example.com/privacy
If I try to rewrite these too the user is always redirected to https://example.com/privacy.php
How do I prevent my server to show the actual filename instead of its rewritten url?
My code looks like this:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\. [NC,OR]
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [R=301,L,NE]
RewriteRule ^checkout checkout.php [L]
RewriteRule ^imprint imprint.php [L]
RewriteRule ^privacy privacy.php [L]
RewriteRule ^terms terms.php [L]
RewriteRule ^allergy allergy.php [L]
RewriteRule ^nutrition nutrition.php [L]
RewriteRule ^order/([A-Z]*)?$ confirmation.php?lang=&id=$1 [L,QSA]
Any help is appreciated.
Regards
Have it this way:
Options -MultiViews
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\. [NC,OR]
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [R=301,L,NE]
RewriteRule ^(checkout|imprint|privacy|terms|allergy|nutrition)/?$ $1.php [L]
RewriteRule ^order/([a-z]+)/?$ confirmation.php?lang=&id=$1 [L,QSA,NC]
Make sure to test after clearing your browser cache. Problem appears to be due to your patterns not using end anchor.
I have combined your multiple similar rules into one rule.
I have this code in my .htacces file:
RewriteCond %{QUERY_STRING} \\?s=([^&]+) [NC]
RewriteRule ^$ job\?search_keywords=%1 [NC,R,L]
And it works well for: example.com/?s=blabla
Now I would like to add that if the url contains /en/:
https://example.com/en/?s=blabla
change for https://example.com/en/work/?search_keywords=blabla
Somone could help me with it? Because my trying gives me ERROR 500.
You just need another rule to handle new URI pattern:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^s=([^&]+) [NC]
RewriteRule ^$ /job?search_keywords=%1 [R=301,L]
RewriteCond %{QUERY_STRING} ^s=([^&]+) [NC]
RewriteRule ^en/?$ /en/work/?search_keywords=%1 [R=301,L]
Note that \\? in your RewriteCond is redundant as QUERY_STRING variable doesn't contain ?
I have form with two parameters city,keyword which are passed to search.php ,after submitting it redirects to url like
website.com/search/lenovo+laptop+dealers/Delhi
But i need url to be parsed without those plus signs but with a dash in url
Example: website.com/search/lenovo-laptop-dealers/Delhi
Code in my htaccess file
RewriteEngine on
RewriteBase /
RewriteCond %{THE_REQUEST} \s/+search\.php\?keyword=([^&]+)&city=([^\s&]+) [NC]
RewriteRule ^ /search/%1/%2? [R=301,L,NE]
RewriteRule ^search/([\w-]+)/([\w-]+)/?$ /search.php?keyword=$1&city=$2 [L,QSA]
You can have your rules like this:
RewriteEngine on
RewriteBase /
RewriteRule "^(search)/([^+]*)\++([^+]*\+.*)$" /$1/$2-$3 [L,NC]
RewriteRule "^(search)/([^+]*)\+([^+]*)$" /$1/$2-$3 [L,R=301,NE,NC]
RewriteCond %{THE_REQUEST} \s/+search\.php\?keyword=([^&]+)&city=([^\s&]+) [NC]
RewriteRule ^ /search/%1/%2? [R=301,L,NE]
RewriteRule ^search/([\w-]+)/([\w-]+)/?$ /search.php?keyword=$1&city=$2 [L,QSA]
I'm having an issue with a rather old siye. I have some generic URL's with a query string, that i want to 301 redirect, but I don't want to blanket re-direct the urls. I want to choose where each query string is being redirected as there are alot of different categories within the site. For example:
I want to change:
index.php?_a=viewCat&catId=199
to:
/garden-furniture/patio-furniture/garden-benches-garden-seats/cat_199.html
But ill want to change another catid to another URL of my choosing, completely different structure. The problem I'm having is with the code i've got, if I don't have a ? at the end of the destination url, it works, but appends the query string to the end, if I put it on the end, it doesn't redirect at all.
Code I'm using:
RewriteCond %{QUERY_STRING} ^_a=viewCat&catId=199
RewriteRule ^index\.php$ /garden-furniture/patio-furniture/garden-benches-garden-seats/cat_199.html? [L,R=301]
Any help would be appreciated!
EDIT: The rest of my htaccess
RewriteEngine On
RewriteRule ^conservatory/(.*)$ /conservatory-furniture/$1 [R=301,L]
RewriteRule ^dining-room/(.*)$ /dining-room-furniture/$1 [R=301,L]
RewriteRule ^garden/(.*)$ /garden-furniture/patio-furniture/$1 [R=301,L]
RewriteBase /
RewriteCond %{QUERY_STRING} (.*)$
RewriteRule cat_([0-9]+)(\.[a-z]{3,4})?(.*)$ index.php?_a=viewCat&catId=$1&%1 [NC]
RewriteCond %{QUERY_STRING} (.*)$
RewriteRule prod_([0-9]+)(\.[a-z]{3,4})?$ index.php?_a=viewProd&productId=$1&%1 [NC]
RewriteCond %{QUERY_STRING} (.*)$
RewriteRule info_([0-9]+)(\.[a-z]{3,4})?$ index.php?_a=viewDoc&docId=$1&%1 [NC]
RewriteCond %{QUERY_STRING} (.*)$
RewriteRule tell_([0-9]+)(\.[a-z]{3,4})?$ index.php?_a=tellafriend&productId=$1&%1 [NC]
RewriteCond %{QUERY_STRING} (.*)$
RewriteRule _saleItems(\.[a-z]+)?(\?.*)?$ index.php?_a=viewCat&catId=saleItems&%1 [NC,L]
If these are complete URLs, you could anchor the pattern at the start of the string
RewriteRule ^cat_([0-9]+)(\.[a-z]{3,4})?(.*)$ index.php?_a=viewCat&catId=$1&%1 [NC]
this would prevent an URL, which has cat_ inside being rewritten to index.php?....
And since you don't use the trailing optional part, you could eliminate this too
RewriteRule ^cat_([0-9]+) index.php?_a=viewCat&catId=$1&%1 [NC]
Another point is the RewriteCond with query string. If the query string is optional, you could remove the RewriteCond and modify the RewriteRules to
RewriteRule ^cat_([0-9]+) index.php?_a=viewCat&catId=$1 [QSA,NC]
So, all these would become
RewriteRule ^cat_([0-9]+) index.php?_a=viewCat&catId=$1 [QSA,NC]
RewriteRule ^prod_([0-9]+) index.php?_a=viewProd&productId=$1 [QSA,NC]
RewriteRule ^info_([0-9]+) index.php?_a=viewDoc&docId=$1 [QSA,NC]
RewriteRule ^tell_([0-9]+) index.php?_a=tellafriend&productId=$1 [QSA,NC]
RewriteRule ^_saleItems index.php?_a=viewCat&catId=saleItems [QSA,NC,L]
Im trying to figure out how to mask all urls on my site to make them "pretty" I would like to replace "tubepress_video" with just "video" and "tubepress_page" to "page" Any help would be greatly appreciated.
Example
http://mydomain.com/?tubepress_video=m3gRH-hPS9I&tubepress_page=1
Do this: This will only work for the links of this format:
http://mydomain.com/?tubepress_video=m3gRH-hPS9I&tubepress_page=1
RewriteEngine on
RewriteBase /
RewriteCond %{QUERY_STRING} ^tubepress\_([^&]+)&tubepress\_([^&]+)$ [NC]
RewriteRule ^ ?%1&%2 [L,R=301]
RewriteCond %{QUERY_STRING} !^tubepress [NC]
RewriteCond %{QUERY_STRING} [^&]+&[^&]+
RewriteRule ^ ?tubepress_%1&tubepress_%2 [L]