So I have my .htaccess ready and working to rewrite my websites link for search query from this:
www.domain.com/search?q=blabla
to this:
www.domain.com/blabla
It works fine if I type something in my url manualy like shown above, but the problem is once user submits the search it shows as
search?q=blabla
and it's not a surprise as my form action has search.php, like so
action="search.php"
So how do I get proper search submition so it will show only a search word instead of search?q=blabla query?
ADDED
My htaccess rules:
Options -Indexes
Options +FollowSymlinks
RewriteEngine On
RewriteRule ^([0-9_-]+)/?$ index.php?id=$1 [L]
RewriteRule ^([^/.]+)/?$ search.php?q=$1 [L]
Add this rule:
RewriteCond %{THE_REQUEST} \ /search(?:\.php|)\?q=([^\ &]+)
RewriteRule ^ /%1? [L,R]
right under RewriteEngine On
Related
I am trying to make a link that looks like https://www.exapmle.com/profile.php?u=8 to look like https://www.exapmle.com/profile/8
I have a tried variations of this in htaccess:
RewriteRule ^/profile/([0-9]+)/?$ profile.php?u=$1
RewriteRule ^/profile/([0-9]+)\.html /profile.php?u=$1
I don't know what i am doing wrong, the links don't change and I'm not getting any errors either
You may use this code in your site root .htaccess:
Options -MultiViews
RewriteEngine On
# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} /profile\.php\?id=([^\s&]+) [NC]
RewriteRule ^ /profile/%1? [R=301,L]
# internal forward from pretty URL to actual one
RewriteRule ^/?profile/(\d+)(?:\.html)?/?$ profile.php?u=$1 [L,QSA,NC]
here i am trying to rewrite url but its not working
> Options +FollowSymlinks RewriteEngine on rewriterule
> ^FAQ.php?view=why_best(.*)$ http://www.bestsports.ca/FAQ/WhyBest$1
> [r=301,nc]
old url is http://www.bestsports.ca/FAQ.php?view=why_best
New Url http://www.bestsports.ca/FAQ/WhyBest should be like this
after editing htacces fiel its opening the same old url please help
thanks
i am trying this code now
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{THE_REQUEST} \s/+FAQ\.php\?view=why_best [NC]
RewriteRule ^ /FAQ/WhyBest/? [R=301,L]
RewriteRule ^FAQ/WhyBest/?$ /FAQ.php?view=why_best [QSA,NC,L]
RewriteRule ^ /FAQ/SizeChart/? [R=301,L]
RewriteRule ^FAQ/SizeChart/?$ /FAQ.php?view=size_chart [QSA,NC,L]
but its showing error
The page isn't redirecting properly
and if i click same link again for FAQ.php?view=why_best its
redirected to
http://www.bestsports.ca/FAQ/WhyBest/FAQ.php?view=why_best
as you helped me i completed the above seo url rewrite problem for my all other website pages
i used the third party cart system from ecwid when i click on any proudct its show this link or url
http://www.bestsports.ca/product.php#!/~/product/category=9414048&id=11484861
how can i rewrite this url insted of showing category id and i want to show name
i already tried your above instruction but its not working can you please explain is it possible to make this url seo friendly url
thank you
You cannot match query string in RewriteRule. Use RewriteCond instead:
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{THE_REQUEST} \s/+FAQ\.php\?view=why_best [NC]
RewriteRule ^ /FAQ/WhyBest? [R=301,L]
RewriteRule ^FAQ/WhyBest/?$ /FAQ.php?view=why_best [QSA,NC,L]
So I'm running into an issue here that I believe I have correct yet it's just not working for me here.
So simple enough I want me current URL which is:
tremorelights.com/chandelier-c-18.html?page=2&osCsid=vtemi4nqlioftbteam6nap0s77
To look like this URL:
tremorelights.com/chandelier/2/
So I'm trying to redirect it to the clean URL and this is what I have now.
RewriteEngine On
RewriteBase /
RewriteRule ^chandelier-c-18.html?page=$1 chandeliers/([0-9]+) [QSA,L,R=301]
Yet this is not working at all. When I manually input the clean URL it does not give me a 404 error but it does not take me to any other page like it should.
You can match against the query string in a rewrite rule, what you want to match against is the %{THE_REQUEST} variable here.
Try:
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} \ /+chandelier-c-18.html\?page=([0-9]+)
RewriteRule ^ chandeliers/%1? [QSA,L,R=301]
then maybe:
RewriteRule ^chandeliers/([0-9]+) chandelier-c-18.html?page=$1 [L]
Change your rule to this:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteRule ^chandeliers/([0-9]+)/?$ chandelier-c-18.html?page=$1&osCsid=vtemi4nqlioftbteam6nap0s77 [QSA,L,NC]
I want to change alle dynamic url's to static ones,
but after rewriting the dynamic url's are still responding/available.
What did I do =>
I found this Tool for SEO:
http://www.webconfs.com/url-rewriting-tool.php
I entered this:
.../filmdetails.html?var=ich_einfach_unverbesserlich_ii
Then I put into my .htaccess this:
RewriteEngine On
Options +FollowSymLinks
RewriteRule ^filmdetails/(.*)/$ filmdetails.html?var=$1
Works, but now I got a problem: This URL is still available and should not be: .../filmdetails.html?var=ich_einfach_unverbesserlich_ii
How do I get rid of the dynamic url's?
Your rule only rewrites the nicer looking URL to the one with a query string. Rules only work from a "pattern" -> "target" way, the mapping won't magically work the other way. You'll have to create a separate rule in order to redirect the browser:
RewriteCond %{THE_REQUEST} ^(GET|HEAD)\ /filmdetails\.html\?var=([^&\ ]+)&?([^\ ]*)
RewriteRule ^ /filmdetails/%2/?%3 [L,R=301]
Try:
Options +FollowSymLinks
RewriteEngine On
#set this to path to your filmdetails.html file (from the document root)
RewriteBase /
#checking if redirect already happened
RewriteCond %{ENV:REDIRECT_PASSED} !^$
RewriteRule $ - [L]
#Your rewrite rule
RewriteRule ^filmdetails/(.*)/$ filmdetails.html?var=$1 [L,E=PASSED:1]
#redirecting from filmdetails.html with query string ?var=something
RewriteCond %{QUERY_STRING} ^var=(.+)$ [NC]
RewriteRule ^filmdetails.html$ filmdetails/%1/? [R]
filmdetails.html?var=something will be redirected to filmdetails/something
RewriteRule new/$ /search.php?category=1
RewriteRule new/\?(.+)$ /search.php?category=1&$1
I'm trying to do something like this, if the following address link is accessed,
http://onlineshop.com/new/
http://onlineshop.com/new/?price_max=30
then it will open this link,
http://onlineshop.com/new/search.php?category=1
http://onlineshop.com/new/search.php?category=1&price_max=30
Unfortunately it is not working this way.
A RewriteRule won't naturally catch query string parameters, you must use this kind of .htaccess :
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^new/$ /search.php?category=1&%1
You can just simply redirect from /new to /search.php with QSA flag and Apache will append the existing query string. Something like this will work for you:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^new/?$ /search.php?category=1 [L,QSA,NC]