My page will open as https://example.com/profile/account.php?act=reviews&user=1. But it's too long. Can I shorten it to https://example.com/profile/1/reviews using .htaccess? Sample codes are not available. But this error is working.
Approximate code
RewriteEngine On
RewriteRule ^profile/([a-zA-Z0-9_-]+)/([a-zA-Z0-9]+)$ /profile/account.php?act=reviews&user=$1 [QSA,L]
Related
How do I get this original URL:
https://www.example.com/search-for-commercial-doors.html?format=json&task=suggestions.suggest&tmpl=component
To be rewritten to:
https://www.example.com/search-for-commercial-doors.html
Code that is not working:
RewriteEngine On
RewriteRule ^search-for-commercial-doors\.html$ /search-for-commercial-doors.html? format=json&task=suggestions.suggest&tmpl=component [L]
With your shown samples, please try following htaccess Rules file. Make sure your htaccess file is present along with search-for-commercial-doors.html in same folder, also clear your browser cache before testing your URLs.
RewriteEngine ON
RewriteCond ^(search-for-commercial-doors\.html)/?$ $1?format=json&task=suggestions.suggest&tmpl=component [NC,QSA,L]
Please help me in writing correct .htaccess code to get the wanted result.
I have the following pages:
www.mydomain.com/?exam=/hp-certification/
www.mydomain.com/?exam=/cisco-certification/
www.mydomain.com/?exam=/oracle-exam-prep/
www.mydomain.com/?exam=/faq/
www.mydomain.com/?exam=/support/
And there are many more pages but you can notice that the fixed part is: www.mydomain.com/?exam=
Instead of using query string links, I want the following links to work as above pages:
www.mydomain.com/hp-certification/
www.mydomain.com/cisco-certification/
www.mydomain.com/oracle-exam-prep/
www.mydomain.com/faq/
www.mydomain.com/support/
and so on.
your link should be like this www.mydomain.com/?exam=hp-certification/ and the rewrite rule would like this in .htaccess file.
RewriteEngine On
RewriteRule ^([^/.]+)$ /?exam=$1 [L]
You can do that by using the following rules in your .htaccess file:
RewriteEngine On
RewriteCond %{QUERY_STRING} exam=(.+) [NC]
RewriteRule ^(.*)$ http://www.example.com/%1? [R=301,NC,L]
So what does the above do?
First, it will take the query exam= as a condition, if this condition is met then it will grab any version of the variable using (.+).
It will then rewrite the URL using 301 redirection to show http://www.example.com/anything/. The use of %1 is to grab the variable from exam= and then we use ? to stop the original query string from appearing on the end of the newly rewritten URL.
Make sure you clear your cache before testing this.
I have written a rewrite rule in the .htaccess file for my website page:
RewriteRule ^nice_url/$ ?p_action=user_profile&post_author=45 [L]
The full link is: "http://www.example.co.il/nice_url/" it works perfect.
BUT, when I try to create a sitemap (e.g. with http://www.web-site-map.com/), I have an indication that the link "http://www.example.co.il/nice_url/" is broken.
Why?
The link is working fine. Why is it indicated as broken?
Thanks!
You can just add another rule to externally redirect long URL to nice URL like this:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+\?p_action=user_profile&post_author=45\s [NC]
RewriteRule ^ nice_url? [R=301,L]
UPDATE: Alright I checked that sitemap generator is putting & instead of & in generated URLs.
You need to add this additional rule to handle this:
# convert & to &
RewriteCond %{QUERY_STRING} ^(.*)&(.*)$ [NC]
RewriteRule ^ %{REQUEST_URI}?%1&%2 [L,R,NE]
Seems that I found the problem:
I have a main .htaccess file that redirects to 3 different folders. Each folder is for a different website (all in the same host).
One of the websites is in WP. The rewrite happens well.
BUT, when I try to generate a sitemap - the wp returns a 404 for the sitemap generator and thats why I get an error.
solution: I'll probably try to rewrite from the php and not from the htaccess.
I have followed this thread.
Question mark in the end of RewriteRule
My requirement was also same.
My page is redirecting(301) properly but it's displaying OBJECT NOT FOUND
My Actual URL
http://mydomain.com/iphone_advanced_search_result.php?keywords=test
My Desired URL
http://mydomain.com/search/test
My HTACCESS Code
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} ^keywords=(.*)$
RewriteRule ^iphone_advanced_search_result\.php$ search/%1? [R=301,L]`
Why am I getting this error? Please Help!
You're matching on a URL that resembles '/iphone_advanced_search_result.php', but your actual URL doesn't contain the '.php', so it doesn't match.
Remove the '.php' check from your rule and it should work fine.
If your desired url to be used by the user is
http://mydomain.com/search/test
and your processing script is
http://mydomain.com/iphone_advanced_search_result.php?keywords=test
Your rewrite should be the other way round like below:
RewriteEngine on
RewriteBase /
RewriteRule ^search/(.+)$ iphone_advanced_search_result.php?keywords=$1 [L]
There is plenty of information out there but nothing I've read on the interwebz has given me an answer as to why my htaccess is not working.
I cannot determine why my rule isn't rewriting the URL as I thought it would. I have the following url:
domain.com/Book/bookpage/index.php?bookID=123&bookName=foo_bar
I would like to change it so that when someone hits that URL, it shows like:
domain.com/Book/123/foo_bar
I started off trying to get it to work using just the Book ID and haven't even gotten that to work.
This is what I have thus far:
RewriteRule ^Book/([0-9]+)$ /Book/bookpage/index.php?bookID=$2
However, after placing that htaccess in the root of the site and going to the URL:
domain.com/Book/bookpage/index.php?bookID=123
The URL in the address bar remains the same.
try this:
RewriteEngine On
RewriteBase /
# this rewrite domain.com/Book/123 or domain.com/Book/123/
RewriteRule ^Book/([0-9]+)/?$ /Book/bookpage/index.php?bookID=$2 [L,NC,QSA]
# this rewrite domain.com/Book/123/title or domain.com/Book/123/title/
RewriteRule ^Book/([0-9]+)/([a-z0-9\-_]+)/?$ /Book/bookpage/index.php?bookID=$1&bookName=$2 [L,NC,QSA]
Try adding [L,R=301] at the end of the line:
RewriteRule ^Book/([0-9]+)$ /Book/bookpage/index.php?bookID=$2 [L,R=301]