url rewriting with QUERY_STRING - .htaccess

I would like to rewrite http://example.com/test/index.php?id=123
to http://example.com/test/item/123/ and http://example.com/test/index.php?id=123 redirect to the human friendly url.
I don't know what is wrong in my htaccess :
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /test/
RewriteCond %{QUERY_STRING} ^id=([a-z0-9]+)$ [NC]
RewriteRule ^/item/%1/? [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^item/([a-z0-9]+)/$ index.php?id=$1 [L]

You can use the following RewriteRule in your /test/.htaccess file
Options +FollowSymLinks -MultiViews
RewriteEngine on
#redirect old url to the new one
RewriteCond %{THE_REQUEST} /test/index\.php\?id=([^\s]+) [NC]
RewriteRule ^ /test/item/%1? [L,R=301]
#internally map new url to the old one
RewriteRule ^item/(.+)/?$ /test/index.php?id=$1 [L,NC]

Related

301 Redirect Dynamic URL

OK so I have the following as part of the URL: /user/26872-essi/
and I'm going to final URL of /essi/
I currently have:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^user\/([0-9]+)\-.+[/]?$ /user.php?user_id=$1
So I tried:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^user\/([0-9]+)\-.+[/]?$ /$2/ [R=301,L]
RewriteRule ^(((?!\.|\/).){1,})\/?$ /user.php?username=$1
It doesn't seem to be passing the variable in. Any ideas what I could be doing wrong?
You may use these rules in your site root .htaccess:
RewriteEngine On
RewriteRule ^user/\d+-([\w-]+)/?$ /$1/ [R=301,NC,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([\w-]+)/?$ user.php?username=$1 [L,QSA]

Htaccess rewrite rules with pictures

Here are my rewrite script (.htaccess)
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^(action|ajax|api|uploads)(.*)$ - [L]
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^.*$ ./index.php
Now I have the url: http://domain.tld/uploads/users/1/pictures/1443563069.jpg
The picture exist, but i can't load it. Is something with my rewrite rule not ok?
Try this code in root .htaccess:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{THE_REQUEST} /(action|ajax|api|uploads) [NC]
RewriteRule ^ - [L]
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^ index.php [L]
Using %{THE_REQUEST} because REQUEST_URI changes to /index.php in your last rule.

Again stuck with HTACCESS

What am I doing wrong here? It does not work for me :(
Options +FollowSymLinks -MultiViews
RewriteEngine on
# use appropriate rewrite base
RewriteBase /stage/customer/be/
RewriteCond %{REQUEST_METHOD} !^(TRACE|TRACK|GET|POST|HEAD)$
RewriteRule ^ - [F]
RewriteCond %{THE_REQUEST} /index\.php\?action=([\w-]+)&template_id=([\w-]+)&feedbackTypeID=([\w-]+) [NC]
RewriteRule ^ %1/%2/%3? [L,R]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([\w-]+)/([\w-]+)/([\w-]+)/?$ index.php?action=$1&template_id=$2&feedbackTypeID=$3 [L,QSA]
This is a continutation of this thread again a new .htaccess issue
I have this code in the htaccess one folder above from where the call is being made. Not sure if this would affect the "be" folder as well.
Options +FollowSymLinks -MultiViews
RewriteEngine on
# use appropriate rewrite base
RewriteBase /stage/customer/
RewriteCond %{REQUEST_METHOD} !^(TRACE|TRACK|GET|POST|HEAD)$
RewriteRule ^ - [F]
RewriteCond %{THE_REQUEST} /index\.php\?id=([\w-]+)\s [NC]
RewriteRule ^ %1? [L,R]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([\w-]+)/?$ index.php?id=$1 [L,QSA]

Create a pretty url without touching the file

Is it possible to create a pretty url without having to touch the file itself? For example:
http://sawebdev01/company/news-events/press-releases/press-release/?pr=168#.Uajh_kCyBSK
And convert it to:
http://sawebdev01/company/news-events/press-releases/pr/168
I tried this, and it does not seem to work:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{THE_REQUEST} /company/news-events/press-releases/press-release/?pr=([^&]+) [NC]
RewriteRule .* /company/news-events/press-releases/press-release/pr/%1? [R=301,L]
Try this code:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} \s(/company/news-events/press-releases)/press-release/\?pr=([^&]+) [NC]
RewriteRule ^ %1/pr/%1? [R=302,L]
RewriteRule ^(company/news-events/press-releases)/pr/([^/]+)/?$ /$1/press-release?pr=$2 [L,NC,QSA]

Rewrite with htaccess not working

i have a site wich have a dynamic url for 3 pages only. and for that i dont go for php function. So I decided to go for .htaccess rewrite rules but I am not having any luck yet.
This is my actual url: /index.php?mode=service&inid=1
I want to rewrite it to this: /home-theater
I try it my self and with this code:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.mysite\.com.au$ [NC]
RewriteRule ^(.*)$ http://www.mysite.com.au/$1 [L,R=301]
Options +FollowSymLinks
DirectoryIndex index.php
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
RewriteRule ^index\.php$ http://www.mysite.com.au/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^home-theater/?$ index.php?mode=service&inid=1 [L,NC,QSA]
I still can't get it to work.
Also I write index.php to www redirect before this code, so I guess if it cause any issue or not. index.php to www site redirects work perfectly but this is not working.
Use L flag like this:
RewriteRule ^home-theater/?$ index.php?mode=service&inid=1 [L,NC,QSA]
Remember this will not change the URL in the browser since this will internally forward request to your index.php.
Also if this doesn't work then provide your full .htaccess in your question.
Update: I have modified your .htaccess here, please try it out now after clearing your browser cache:
DirectoryIndex index.php
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\.mysite\.com.au$ [NC]
RewriteRule ^(.*)$ http://www.mysite.com.au/$1 [L,R=301]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
RewriteRule ^ http://www.mysite.com.au/ [R=301,L]
RewriteRule ^home-theater/?$ index.php?mode=service&inid=1 [L,NC,QSA]
RewriteCond %{ENV:REDIRECT_STATUS} !200
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ /index.php [L]

Resources