REQUEST_URI redirect issue - .htaccess

RewriteEngine On
RewriteCond %{REQUEST_URI} team
RewriteRule ^ http://sitename.co.uk/about? [L,R=301]
The code above works perfectly if the url is /team/
BUT
if the URL is /team/john-smith/ I do not get redirected?
I can't figure out why this wouldn't work! Any ideas??
Thanks in advance

Have this rule with THE_REQUEST as your top rule:
RewriteEngine On
RewriteCond %{THE_REQUEST} team [NC]
RewriteRule ^team http://sitename.co.uk/about? [L,R=301,NC]
Make sure to use a new browser for testing or completely clear browser cache.

Related

how to hide id = from url using htaccess file

I need the url
from
localhost/project/category?c=electronics
to
localhost/project/category/electronics
I have tried
RewriteRule ^category/([^/\.]+)?$ /category.php?c=$1 [L]
RewriteRule ^category/+?$ /category.php?c=$1 [NC,L]
With your shown samples and attempts please try following htaccess rules. Please do clear your browser cache before testing your URLs.
RewriteEngine ON
RewriteBase /
##External redirect to url change in browser.
RewriteCond %{THE_REQUEST} \s/(project/category)\.php\?c=(\S+)\s [NC]
RewriteRule ^ /%1/%2? [R=301,L]
##Internal rewrite to category.php in backend.
RewriteCond %{DOCUMENT_ROOT}/$1/$2.php -f
RewriteRule ^([^/]*)/([^/]*)/([^/]*)/?$ %{DOCUMENT_ROOT}/$1/$2.php?c=$3 [QSA,L]
RewriteEngine on
RewriteBase /
RewriteRule ^project/category/([0-9a-z]+)$ /project/category?c=$1 [L]
Why is "project/" missing in your original try ?
You have to specify the full path.
You can try this simple rewriteRule wich should works.

How can i redirect /?lang=en|ru to /?lang=en#googtrans(en|ru)?

How can I add the Google translate parameter #googtrans(en|de) or other language, so the translation happens automatically?
Basically, when the user goes to https://example.com/page/?lang=de they are redirected to https://example.com/page/?lang=en#googtrans(en|de)
I use this .htaccess rule, but it's not working:
RewriteCond %{QUERY_STRING} ^lang=([a-z]{2})$
RewriteRule ^/?lang=en#googtrans(en|[a-z]{2}) [R=301,L]
EDIT: Adding edited Rules here.
RewriteEngine ON
RewriteCond %{THE_REQUEST} \s/page/?\?lang=([a-z]{2})\s [NC]
RewriteRule ^ page/?lang=%1#googtrans(%1) [R=301,L,NE]
With your shown samples(this is considering that you are hitting URL like: https://example.com/page/?lang=de in browser), please try following .htaccess Rules file. Please make sure to clear your browser cache before testing your URLs.
RewriteEngine ON
RewriteCond %{QUERY_STRING} ^lang=([a-z]{2})$ [NC]
RewriteRule ^page/?$ page/?lang=%1#googtrans(%1) [R=301,L,NE]

Right rule for html pagination

I have rewrite:
RewriteRule (.*\.html$) /index.php?$1 [L,QSA]
but some pages have pagination, for example
/test.html?page=2
i need to rewrite it to test-page2.html
i tried
RewriteRule (.*)-page([0-9]*)\.html$ /index.php?$1&page=$2 [NC,L]
but it is not working
With your shown samples, please try following. Please make sure to clear your browser cache before testing your URLs.
RewriteEngine ON
##new rule added by me. This will check if a url has html as well as query string then it will rewrite it to html file.
RewriteCond %{THE_REQUEST} \s/([^.]*)\.html\?(page)=(\d+)\s [NC]
RewriteRule ^ %1-%2%3.html [R=301,L]
##OP's previous rule.
##For safer side you could add an additional condition here too.
RewriteCond %{QUERY_STRING} ^$
RewriteRule (.*\.html)$ /index.php?$1 [L,QSA]
Does this work for you?
RewriteEngine on
RewriteCond %{QUERY_STRING} ^([^&]+)&page=([0-9]+)$ [NC]
RewriteRule ^index\.php$ /%1-page%2.html? [L,R]
RewriteRule ^([^-]+)-page([0-9]+)\.html$ /index.php?$1&page=$2 [END]
Make sure to clear your browser cache or use different browser to test this code.

mod_rewrite do not change links when rewrite

I have the following to my .htaccess
RewriteEngine on
RewriteRule ^page/([^/\.]+)/?$ index.php?page=$1 [L]
When I call www.mydomain.com/page/myvalue I get the correct result. In order to to that though I'll need to change all links to my website correct?
Is there a way to accomplish the opposite i.e. when I call index.php?page=$1 to redirect me to www.mydomain.com/page/myvalue ?
Add this rule to your .htaccess:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+index\.php\?page=([^\s&]+) [NC]
RewriteRule ^ page/%1? [R=301,L]

.htaccess code for dynamic redirect

I've having a bit of trouble figuring out how to mass redirect a lot of files.
http://www.mysite.com/verify.php?site=mydomain.com
to
http://www.mysite.com/verify/mysite.com
And of course "mysite.com" will always be a different domain so that should be dynamic.
This is the code that I was using:
RedirectMatch 301 ^/verify\.php\?site=([a-zA-Z0-9\.\-]+)$ /verify/$1
Can someone please post what I need to change to make this work or a correct version of my code above? Thanks for your time!
Try this:
EDIT:
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^verify/(.*)$ verify.php?site=$1 [L]
Then try to load this in browser:
http://www.mysite.com/verify/mysite.com
Try one of the following:
RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /verify\.php\?site=([^&\ ]+)
RewriteRule ^ /verify/%1 [L,R=301]
Or
RewriteEngine On
RewriteCond %{QUERY_STRING} ^site=([^&]+)
RewriteRule ^/?verify\.php$ /verify/%1 [L,R=301]

Resources