I use .htaccess to rewrite the URL
Options +FollowSymlinks
RewriteEngine On
RewriteRule ^book/([^/]*)$ /book.php?book=$1 [NC,L]
This works great, and if I type http://www.domain.org/book/title1 in a browser's address bar it takes me there. But when I click the link on the index page it takes me to the old address http://www.domain.org/book.php?book=title1
It is because you don't have any rules that does the redirect. Have it this way:
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{THE_REQUEST} \s/+book\.php\?book=([^\s&]+) [NC]
RewriteRule ^ /book/%1? [R=302,L,NE]
RewriteRule ^book/([^/]+)/?$ book.php?book=$1 [NC,L,QSA]
Related
I was trying to rewrite a URL for making my site SEO friendly, but .htaccess rewrite not seems to work.
My URL is
www.tasteofkochi.com/dine-detail.php?a=150
I need this to look like
www.tasteofkochi.com/sometext/150
I did the simple formula but it's not reflecting, intact nothing happens at all. If I add some junk char in htaccess, site crashes, which means htaccess is working fine. Also I added a formula to remove .php extn, and that too works fine. Only issue is with this one. Can anyone please help me. I enable rewrite in httpd and allow all in directories, still not working.
Below is my .htacces
RewriteEngine on
Options +FollowSymLinks -MultiViews
RewriteBase /
## hide .php extension
# To externally redirect
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L,NC]
## To internally redirect
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [L]
RewriteRule ^detail/([0-9]+)/?$ dine-detail.php?a=$1 [NC,L]
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*) index.php?p=$1 [L,QSA]
We can create pretty urls with .htaccess and php by mainly two files one is .htaccess and another index.php
Example
I would like to change the URL
/index.php?main_page=product_info&cPath=1&products_id=4
to
/index.php?main_page=product_info&cPath=141&products_id=302
I have tried
RewriteRule ^products_id=4$ products_id=302
but that doesn't seem to match.
My .htaccess file currently contains
RewriteEngine on
Options +FollowSymLinks
RewriteRule ^products_id=302$ products_id=4 [L,R=301]
It would seem like I could use something like
RewriteCond %{QUERY_STRING} ^(([^&]*&)*)products_id=4(&.*)?$
RewriteRule ^index\.php$ /index.php?%1products_id=302%3 [L,R=301]
but that doesn't work reliably. (If I click on a link, it doesn't work, but if I enter that URL in the address bar, it does.)
Try the following rule :
RewriteEngine on
RewriteCond %{THE_REQUEST} /index\.php\?main_page=([^&]+)&cPath=1&products_id=4\sHTTP [NC]
RewriteRule ^ /index.php?main_page=%1&cPath=141&products_id=302 [L,R]
I need to clean url for my web site.
The structure is like this :
example.com/home
inside the home folder I have:
index.php
ambiente.php
.htaccess
This is my .htaccess code:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+ambiente\.php\?ambiente=([^\s&]+) [NC]
RewriteRule ^ ambiente/%1? [R=301,L]
RewriteRule ^ambiente/([^/]+)/?$ ambiente.php?ambiente=$1 [L,QSA]
I would like the file did this:
example.com/home/ambiente.php?ambiente=living
example.com/home/ambiente/living
The problem is that the URLs are not automatically rewritten.
If I click on the ambiente.php?ambiente=living link in the index file, in the address bar I find example.com/home/ambiente.php?ambiente=living.
If I write in the address bar: http://example.com/home/ambiente/living, it works properly!
How can I solve this?
Your Rewritecondition matches /ambiente.php?ambiente=foobar but it does not match the orignal uri /home/ambiente.php?ambiente=foobar Replace your first rewriteRule with the following
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+home/ambiente\.php\?ambiente=([^\s&]+) [NC]
RewriteRule ^ /home/ambiente/%1? [R=301,L]
What I think should be simple is just not working.
I have switched domains
Old URL example:
digital.photorecommendations.com/recs/2015/01/big-zoom-field-review/
New URL example:
photorec.tv/2015/01/big-zoom-field-review/
Really just switching domain and dropping the recs folder from the URL
Using http://htaccess.madewithlove.be/ to test and the outputs the correct URL
Options +FollowSymlinks
RewriteEngine on
RewriteBase /recs
RewriteCond %{HTTP_HOST} !^www\.digital.photorecommendations\.com$ [NC]
RewriteRule ^recs(.*) http://photorec.tv/$1 [L,R=301]
When I place this in the htaccess file I get 404 errors on all the pages except the home page. The htaccess file is inside the /recs folder. I have also tried it in the root directory of digital.photorecommendations.com and I get no results at all.
Any suggestions?
Thanks!
You have wrongly used negation in RewriteCond and regex also needs a fix. Use this rule in /recs/.htaccess:
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?digital\.photorecommendations\.com$ [NC]
RewriteRule ^(index\.php)?$ http://photorec.tv/ [L,R=301,NC]
RewriteCond %{HTTP_HOST} ^(www\.)?digital\.photorecommendations\.com$ [NC]
RewriteRule ^(.+)$ http://photorec.tv/recs/$1 [L,R=301,NC,NE]
we have a website in English. Now we want to have a translated copy of this website in German.
The index.html is located in the root folder: www.mydomain.com/index.html
Now I want to create a htaccess file which redirects all user which have set the preferred language in their browser to German (de, de-de, de-at, de-ch) to www.mydomain.com/de/index.html. All other user should be redirected to www.mydomain.com/en/index.html.
I tried a lot but I can't make it work. I do not really understand the regular expression thing and it's usage.
Most of the tries ended up with error 403 or 500. The current htaccess doesn't end up in an error, but it doesn't work.
The htaccess is now:
Options -Indexes +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP:Accept-Language} ^de [NC]
RewriteRule ^/(.*)$ /de/$1 [L]
RewriteRule ^/(.*)$ /en/$1 [L]
It seems like the file doesn't work at all. When I open www.mydomain.com it opens www.mydomain.com/index.html
Htaccess and rewriting works in general:
RewriteRule ^(.*)$ http://www.google.com/ [R=301,L]
works.
If I delete the slash behind ^
RewriteRule ^(.*)$ /en/$1 [L]
I get an error 500.
What do I do wrong?
I actually want the server to redirect to the webpage which the user tried to open. So if the user opens mydomain.com/index2.html he should be redirected to mydomain.com/xx/index2.html (and not to index.html)
Any ideas?
Thanks,
Jaroslaw
You can use this rule:
Options -Indexes +FollowSymLinks
RewriteEngine On
RewriteRule ^(en|de)/ - [L,NC]
RewriteCond %{HTTP:Accept-Language} ^de [NC]
RewriteRule ^(.*)$ /de/$1 [L]
RewriteRule ^(.*)$ /en/$1 [L]