i am trying to change the url using htaccess rewrite
i want to change this url
page/details.php?name=abcdef&id=18
to
page/abcdef
Here my sample code for this
RewriteEngine On
RewriteRule ^company/([A-Za-z0-9-]+)/$1 company/details.php?name=$1&id=$2 [R=301,L]
this is not working, and also i was tried many code but not working,please help me to find htaccess code for this url
Thanks advance
This should do what you're after:
RewriteCond %{QUERY_STRING} ^.*name=([a-zA-Z0-9]*).*$
RewriteRule ^page/(.*)$ page/%1? [R=301,L]
Try this one:
RewriteEngine on
RewriteCond %{QUERY_STRING} ^name=(.*)&id=(.*)$
RewriteRule ^page/(.*)$ /page/%1? [R=301,L]
This will check for these 2 parameters in the query string.
Related
I have lot or articles with this URL format:
mydomain/art/details.php?articleid=24463&parentid=1&catid=166
the above is an example.
And i want that redirect these kind of URL to :
mydomain/art/24463.html
Please let me know that how can i do it with .htaccess?
Thanks in advance
Instead of mydomain/art/24463.html you should choose something like mydomain/art-166/1-24463.html.
This way, you'll include also parentid and catid which are dynamic parameters (and so, needed for rewriting).
RewriteEngine On
RewriteCond %{THE_REQUEST} \s/art/details\.php\?articleid=(\d+)&parentid=(\d+)&catid=(\d+)\s [NC]
RewriteRule ^ /art-%3/%2-%1.html? [R=301,L]
RewriteRule ^art-(\d+)/(\d+)-(\d+)\.html$ /art/details.php?articleid=$3&parentid=$2&catid=$1 [L]
Try this in htaccess tester
RewriteEngine on
RewriteRule ^art/(\d+).html$ art/details.php?articleid=$1&parentid=1&catid=166 [nc]
Is it possible to redirect based on an url that would be as:
www.url.com/stuff.php
But not redirect if the url contained any characters after the php, as such:
www.url.com/stuff.php?variables=values&othervariable=othervalue&etc=more
I have no clue how to wriite this either.
Thanks in advance!
Edit: basically I need the redirect to happen to www.url2.com only if www.url.com ends with .php, but not if the .php is followed by variables.
try
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^/site.com/?$ /site.com/cart.php [R=301,NC,L]
Try:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^/?cart.php$ / [L,R=301]
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^stuff.php$ RELATIVE_OR_ABSOLUTE_URL_HERE [L]
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]
I search many topic about htaccess but still not success.
I want when people type address:
http://domain.com/?q=filename1
http://domain.com/?q=filename2
...
It will auto redirect to:
http://domain.com/download/filename1.html
http://domain.com/download/filename2.html
...
I try:
RewriteEngine On
RewriteRule ^/?q=(.*)$ /download/$1.html [L,R=301]
But it is not working. How can I fix this?
Using this may be helpful:
RewriteEngine On
RewriteCond %{QUERY_STRING} q=(.*)
RewriteRule ^q(.*) /download/%1.html [L,R=301]
EDIT:
Try this :)
RewriteEngine On
RewriteCond %{QUERY_STRING} q=(.*)
RewriteRule ^(.*) /download/%1.html? [L,R=301]
By using ? query string will be removed ;)
I have a dynamic query string that I need to pass via an .htaccess redirect. For example:
I need to redirect this URL: http://mysite.com/page1?action=signup&var2=dynamicVar
To this: http://mysite.com?action=signup&var2=dynamicVar
I know this is pretty simple, but I'm really not sure what type of rule/syntax would work for this.
Any help is greatly appreciated!
If you already have .htaccess then simply add this line:
RewriteRule ^page1/?$ page2 [L,R,QSA,NC]
Update: Based on your comments:
RewriteCond %{QUERY_STRING} (^|&)action=signup(&|$) [NC]
RewriteRule ^page1/?$ / [L,R,QSA,NC]
RewriteRule ^page1(.*)$ /page2$1 [L,R=301]
Input
http://mysite.com/page1?action=signup&var2=dynamicVar
this is the rewrite rule
RewriteRule ^page1?(.*)$ /?$1 [L,R=301]
redirect to
http://mysite.com/?action=signup&var2=dynamicVar
this will redirect all request o page1 with get parameters to http://mysite.com
Use %{REQUEST_URI}
fi.:
RewriteCond %{HTTP_HOST} ^website\.(.+)$ [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
rewrites anything that starts with "website" to "www.website..." including the querystring (by use of %{REQUEST_URI})