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.
Related
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 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]
I have this url http://subdomain.domain.com/index.php?page=print-items and I want to remove index.php?page= and only keep what comes after it.
I tried this but it didn't work. it only removes index.php and keeps ?page=print-items
RewriteEngine On
RewriteRule ^([a-z0-9]+) index.php?page=$1
Could you please try following, written and tested as per shown samples.
RewriteEngine ON
RewriteCond %{THE_REQUEST} index\.html\s [NC]
RewriteRule ^(.*/?)/?$ index.html?page=$1 [NC,L]
OR if you are hitting usre friendly URL and you want to redirect in backend into index.html URL with query string then try following.
RewriteEngine ON
RewriteCond %{THE_REQUEST} !index\.html\s [NC]
RewriteRule ^(.*/?)/?$ index.html?page=$1 [NC,L]
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.
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]