Hello guys! I need some help with htaccess, because I'm really stuck with it. I have some pages, like:
site.ru/books
site.ru/pens
And those links can be called by other urls:
site.ru/index.php?show=books
site.ru/index.php?show=pens
I hope you understand those links above are equal. Just, urls are user friendly.
I want to use RewriteCond to make a redirect from "site.ru/index.php?show=books" to "site.ru/books", because Google or other Search Engines don't like duplicate pages.
But the problem is I don't know how to write this… Help me please, and sorry for my bad English ;-)
put this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} \s/+index\.php\?show=([^\s&]+) [NC]
RewriteRule ^ %1? [R=302,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/?$ index.php?show=$1 [L,QSA]
Related
Hi! My english is not very good, sorry for any spelling mistakes.
Using .htaccess I want to add www. and remove/hide the .html.
It should look something like this:
BEFORE -- http://example.com/whatever.html
AFTER ----- http://www.example.com/whatever
I have .www adder:
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1
And .html remover
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\.html$ /$1 [N]
How to connect them?
NOTE: It want remove/hide .html from each .html file on my page.
I use this tool to test my .htaccess file: https://htaccess.madewithlove.be
Thanks for any help.
Could you please try following, based on your shown samples only. please make sure you clear your browser cache before testing your URLs. As per Mr.White's nice suggestion added condition in RewriteRule part to avoid passing css or js files to rule.
RewriteEngine ON
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule !\.\w{2,4}$ http://www.%{HTTP_HOST}%{REQUEST_URI}.html [L]
I need to get the following URL rewrite syntax correct and am struggling.
xxxxx.com/public_html/food/
Needs to be rewritten as:
xxxxx.com/food/
I tried this and it doesn't work:
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/public_html/food/(.*)$
RewriteRule ^(.*)$ http://xxxxx.com/food/%1 [R=301,L]
My client is using Joomla (which I am not familiar with), so I need to do so using the .htaccess file per everything I have researched so far. I am just struggling getting the syntax to work correctly though.
Thanks!
Try this, .htaccess
for Rewrite
RewriteEngine On
RewriteRule ^food/?(.*)$ http://xxxxx.com/public_html/food/$1 [QSA,L]
for Redirect (add R=301)
RewriteEngine On
RewriteRule ^food/?(.*)$ http://xxxxx.com/public_html/food/$1 [R=301,QSA,L]
Edit:
If you want to rewrite all urls (including /food)
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/public_html/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /public_html/$1 [QSA,L]
It will allow you to access site like,
http://xxxxx.com/food/ will point to http://xxxxx.com/public_html/food/
http://xxxxx.com/sample/ will point to http://xxxxx.com/public_html/sample/
http://xxxxx.com/anything/cool/?product=123 will point to http://xxxxx.com/public_html/anything/cool/?product=123/
I was wondering how I could give each user a custom page like on YouTube where they have YouTube.com/users/Username
My approach would be to modify an .htaccess file so if I had www.domain.com/cgi-bin/user.py?username=x, and someone wrote in the url www.domain.com/users/x, it would direct them to that page above. I'm just not sure exactly how to write an .htaccess to meet that criteria.
Any help would be great.
Thanks!
The code below should work:
RewriteEngine On
RewriteCond %{THE_REQUEST} ^(GET|POST)\ /cgi-bin/user\.py\?username=(.*)\ HTTP
RewriteRule ^ /users/%2\? [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/users/(.*)\$ /cgi-bin/user.py?username=$1 [L]
Looking for some help with my .htaccess file and mod-rewrite.
I want to make my URLs more friendly.
I would like to take my URLS from:
www.site.com/contact.php
to:
www.site.com/contact/
Any help would be much appreciated?
As you've already mentioned, you need to add an entry to the htaccess.
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^contact /contact.php
Or if you want to do this to all of your php pages then just modify it as following:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
I would like to be able to use rewrite rules to redirect anyone who opens the link :
domain.com/name
to
index.php?username=name
what would be the best way to do it?
I tried to post the htaccess code I wrote but stackoverflow keeps saying it doesn't meet standards so I removed it.
thanks in advance
Something like this will do it:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^/([^/]+)/? [NC]
RewriteRule .* index.php?username=%1 [L,QSA]
It will map silently
http://domain.com/name
To
http://domain.com/index.php?username=name
For this to work, /name must be the first directory in the incoming URL path.