Firstly,Thanks for reading this. How to rewrite the url , in htaccess
For example
wwww.domain.com/home?name=MuhdNazmi <---OLD URL
wwww.domain.com/home/MuhdNazmi <---NEW URL
name is a get variables,
I dont need put .php , since it code for not showing > .php
Try:
RewriteCond %{THE_REQUEST} \ /home\?name=([^&\ ]+)
RewriteRule ^ /home/%1? [L,R=301]
RewriteRule ^home/([^/]+)$ /home?name=$1 [L,QSA]
RewriteEngine On
RewriteRule ^home/([^/]*).php$ /home?name=$1 [L]
If it is a one on redirect then you can follow the below example for you redirect
RewriteEngine on
RewriteCond %{QUERY_STRING} name=MuhdNazmi$ [NC]
RewriteRule ^home/$ /home/MuhdNazmi? [L]
If you want to define it as a generic rule for all the query string parameter modify the above code as
RewriteEngine on
RewriteCond %{QUERY_STRING} name=(.*)$ [NC]
RewriteRule ^home/$ /home/%1? [L]
Related
So i have a htaccess rewrite that makes a query string to a path like so..
RewriteRule ^page/(.*)$ page.php?query=$1
This works fine and using the above i can access the page via both page.php?query= and /page/query/ but how can i make it so that if the page is accessed by the page.php?query= method, it automatically redirects to the path version?
I've tried the following but i don't think i wrote it correctly...
RewriteCond %{HTTP_HOST} ^www\.webaddress\.com\/page\.php\?query\=$
RewriteRule ^(.*)$ http://www.webaddress.com/page/$1 [R=301,L]
Any help to fix this would be appreciated. Thanks.
You can use the following
RewriteEngine On
#url redirection from old url to the new one
#redirect /page.php?query=foo to /page/foo
RewriteCond %{THE_REQUEST} /page.php\?query=([^\s]+) [NC]
RewriteRule ^.+$ /page/%1? [L,R]
#url rewiring from new url to the old one
# rewrite /page/foo to /page.php?query=foo
RewriteRule ^page/(.*)$ page.php?query=$1 [L]
Try it before your internal rewrite rule.
RewriteEngine On
RewriteCond %{REQUEST_URI} ^(.+)\.php
RewriteCond %{QUERY_STRING} ^(.+)\=(.+)
RewriteRule ^ http://%{HTTP_HOST}/%1/%2/%3? [R=301]
I am trying to create a rewrite cond in htaccess
I am trying to redirect
http://www.example.com/business/search-results.php?keywords=Animal+Business+Cards&go=Search
to
http://www.example.com/business/search results.php?keywords=Animal+Business&go=Search
or if possible remove the word "+cards" from any search queries...
what I have tried so far
RewriteEngine On
RewriteCond %{QUERY_STRING} ^Animal+Business+Cards$
RewriteRule ^(.*)$ http://www.example.com/business/search-results.php?keywords=Animal+Business [R=301,L]
also tried
RewriteCond %{QUERY_STRING} "&go=Search" [NC]
RewriteRule (.*) /$1? [R=301,L]
and this
Redirect /business/search-results.php?keywords=Animal+Business+cards&go=Search http://www.example.com/business/search-results.php?keywords=Animal+Business&go=Search
None of these working...
is it possible?
Can any one help?
Thank You in advance
Try the following code :
RewriteEngine On
RewriteCond %{QUERY_STRING} ^keywords=([^\+]+)\+([^\+]+)\+([^&]+)&go=([^&]+)$ [NC]
RewriteRule ^ %{REQUEST_URI}?keywords=%1+%2&go=%4 [NC,L,R]
Another solution
RewriteEngine On
RewriteCond %{THE_REQUEST} \?keywords=([^\+]+)\+([^\+]+)\+([^&]+)&go=([^&\s]+) [NC]
RewriteRule ^ %{REQUEST_URI}?keywords=%1+%2&go=%4 [NC,L,R]
Note : Redirect directive does not support querystrings in its old path perameter, that is why your last attempt failed. You can use %{QUERY_STRING} or %{THE_REQUEST} variable to match against urls with query strings.
I want to rewrite an URL like http://www.domain.tld/test/page.html?id=1&required=1&foo=bar
to http://www.domain.tld/wrapper.php?url=[FULL REQUEST URL]
in wrapper.php I want $_GET['url'] to be http://www.domain.tld/test/page.html?id=1&required=1&foo=bar
What I've tried so far:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^(.*required=.*)$ [NC]
RewriteRule ^ /wrapper.php?url=http://%{HTTP_HOST}%{REQUEST_URI}?%{QUERY_STRING} [L]
But unfortunately $_GET['url'] is now just http://www.domain.tld/test/page.html?id=1 with the other parameters missing.
How should the correct apache synthax for this look like?
Try adding QSA to the Rewrite rule
[L,QSA]
You can use a rule like this in your root .htaccess:
RewriteEngine On
RewriteCond %{QUERY_STRING} (^|&)required=[^&]+ [NC]
RewriteRule !^wrapper\.php /wrapper.php/http://%{HTTP_HOST}%{REQUEST_URI}#%{QUERY_STRING}? [L,NC]
RewriteCond %{REQUEST_URI} ^(/wrapper\.php)/([^#]*)#(.+)$ [NC]
RewriteRule ^ %1?url=%2\?%3 [L,B]
I am knocking my head how to rewrite get parameters with htaccess.
Here is my htaccess so far (removing only index.php).
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
I want to rewrite the following url http://example.com/?lang=en&dscroll=1200 into http://example.com/en/dscroll/1200. Some htaccess master, please :)?
Thanks
The rule that you have doesn't remove the index.php, it only redirects to a host without the www in front.
As for the other rewrite, you need 2. First, you need to make sure your links in all of your content looks like this:
http://example.com/en/dscroll/1200
instead of the one that has the query string.
Then you need to add, below the rule that you already have, these 2 rules:
RewriteCond %{THE_REQUEST} \ /+\?lang=([^&]+)&([^=&\ ]+)=([^&\ ]+)
RewriteRule ^ /%1/%2/%3? [L,R]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/?$ /?lang=$1&$2=$3 [L,QSA]
I have an URL as :
http://mydomain.com/site/?cmd=home
I want to change the above address to http://mydomain.com/home
i am using .htaccess file like this:
RewriteEngine on
RewriteRule ^([^/\.]+)/?$ /site?cmd=$1 [L]
I am not sure where is the problem?
Thanks in advance
The Rule works the other way around: you want to get from /site/?cmd=home to /home, but with your RewriteRule you are redirecting to /site?cmd= (Probably there is a mistake somewhere?)
If you want to redirect from /site/?cmd=home to /home, like the question states, use the following:
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/site
RewriteCond %{QUERY_STRING} ^cmd=(.*)$
RewriteRule ^(.*)$ /%1/? [R=302,L]
You can use this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteCond %{THE_REQUEST} /site\?cmd=([^\s&]+) [NC]
RewriteRule ^ /%1? [R=301,L]
# internal forward from pretty URL to actual one
RewriteRule ^([^/.]+)/?$ /site?cmd=$1 [L]