How to redirect link with question mark - apache

I need to redirect:
https://www.example.com/wiki/?t=1234 to https://www.example.com/vb/showthread.php?t=1234
"1234" is hundreds of pages with different numbers
I try in .htaccess but doesn't seem to work:
RewriteCond %{QUERY_STRING} t=[0-9]
RewriteRule ^(.*)$ /vb/showthread.php?t=$1 [L]

The number may occur once or more in query string ([0-9]+)
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} ^wiki\/
RewriteCond %{QUERY_STRING} t=([0-9]+) [NC]
RewriteRule (.*) /vb/showthread.php?t=$1 [L]
</IfModule>

Related

htaccess rewrite for only root domain, selected files and selected folders

Been fidling with it my self but I think I am doing it all wrong, please advice:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !\-f
RewriteRule ^folder1(.*)$ https://newdomain.com$1 [L,R=301]
RewriteRule ^folder2(.*)$ https://newdomain.com/$1 [L,R=301]
RewriteRule ^folder3(.*)$ https://newdomain.com/somefolder/$1 [L,R=301]
RewriteRule ^page1\.html https://newdomain.com/$1 [L,R=301]
RewriteRule ^page2\.html https://newdomain.com/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^(www\.)?olddomain\.com$ [NC]
RewriteRule ^/?$ https://newdomain.com/ [L,R=301]
</IfModule>
If I request a page/folder for olddomain.com which is not in .htaccess it should not rewrite.
Does anyone have more skills in .htaccess than me?
Thanks,
Marc
Probably you should prepend an additional condition among the ones about newdomain
RewriteCond %{HTTP_HOST} ^(www\.)?newdomain\.com$ [NC]

htaccess redirect if one query param matches

I'm trying to redirect from /somedir/index.php?action=something&id=x to /index.php?action=something&id=x
Only if action = something. id is dynamic.
Most recently I've tried this with no luck. What is wrong with this?
<IfModule mod_rewrite.c>
RewriteCond %{QUERY_STRING} (^|&)action=something($|&)
RewriteCond %{QUERY_STRING} (^|&)id=($|&)
RewriteRule ^somedir/index\.php$ /index.php?action?something&id=%2$ [NC,R]
</IfModule>
Note: somedir has an index.php and this rule in its htaccess. Will that result in conflicts?
RewriteRule ^.*$ index.php [NC,L]
Try this rule instead of your rule in .htaccess
<IfModule mod_rewrite.c>
RewriteCond %{QUERY_STRING} (^|&)action=something($|&)
RewriteCond %{QUERY_STRING} (^|&)id=x($|&)
RewriteRule ^somedir/index\.php$ /index.php?action=something&id=x [L,R=301]
</IfModule>
The result will not conflict.
You can use:
<IfModule mod_rewrite.c>
RewriteCond %{QUERY_STRING} (?:^|&)(action|id)=([^&]+)&(?:.*&)?(action|id)=([^&]+)(?:$|&) [NC]
RewriteRule ^somedir/index\.php$ /index.php?%1=%2&%3=%4 [NC,L,R=301]
</IfModule>

Redirecting all URLs with additional words between two words to non?

I need a mod-rewrite rule that redirects all URLs that contain anything between town & country to a new url with nothing in between town and country except a dash.
e.g:
http://www.example.com/big-town-4-h-country-2j/
to:
http://www.example.com/big-town-country-2j/
I tried this code but nothing happen:
RewriteEngine on
RewriteRule (.*)town.+country(.*) $1town-country$2
My full htaccess code is:
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example\.com
RewriteRule ^(.*)$ http://www.example.com/$1 [R=permanent,L]
RewriteRule (.*)/$ /?l=$1
RewriteRule (.*)country-(.*)$ country.php?q=$1&l=$2&submit=1
</IfModule>
You should use this rule:
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_URI} !town-country [NC]
RewriteRule ^(.*)town[^/]+country(.*)$ $1town-country$2 [L,R=301]

where to set gwt(Google webmater tool) verification in cakephp

//here is my htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^glamestates\.co\.uk$ [NC]
RewriteRule ^.*$ http://www.glamestates.co.uk%{REQUEST_URI} [R=301,L] # <-- Mind the 'L'!
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
where about to add this google webmaster tools link in my htaccess
glamestates.co.uk/googlec7feca3a4513beef.html
what I have got so far but this doesn't work. I added in line five
RewriteRule ^glamestates\.co\.uk\googlec7feca3a4513beef\.html$ http://www.glamestates.co.uk\googlec7feca3a4513beef.html%{REQUEST_URI} [R=301,L]
I have already put this question here since many day nobody answered
Still not 100% clear about what you're asking, but I think perhaps you want this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^glamestates\.co\.uk$ [NC]
RewriteRule ^googlec7feca3a4513beef\.html$ $0 [L]
RewriteRule ^.*$ http://www.glamestates.co.uk%{REQUEST_URI} [R=301,L] # <-- Mind the 'L'!
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
just need to paste the googlec7feca3a4513beef.html file into Webroot folder rather than Root

mod_rewrite not working for query string redirect

Currently I have one rewrite rule for pretty urls, which is working fine. I tried adding in a second, and it's giving me problems:
# redirect /?p=xyz to /xyz
RewriteCond %{QUERY_STRING} ^p=(.*)$
RewriteRule ^(.*)$ /index.php/%1 [L]
# Removes index.php from ExpressionEngine URLs
RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
The second one is working fine, but the first one is giving me internal server error. Basically I want anything in ?p=* to go to /index.php/*
[Edit] Just to clarify, I need http://domain.com/?p=test to be equivalent to http://domain.com/test/
domain.com/test to domain.com/?p=test
Try this instead:
Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} !p= [NC]
RewriteRule ^([^/]+)/? /?p=$1 [L,NC]
OPTION:
In case it is the opposite:
domain.com/?p=test to domain.com/test/index.php
Try this:
Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} p=([^/]+) [NC]
RewriteRule .* /%1/index.php? [L,NC]
Remove index.php in case it is not needed, like this:
RewriteRule .* /%1/? [L,NC]