redirect htaccess not working - regex

Im trying to some redirects with a site I inherited, I didnt build the original htaccess
Currently when I click in the about link in Google it just takes me a 404 landing page , whereas I want it to take me to about_us page...
RewriteBase /
RewriteRule ^showroom$ index.php?route=showroom/showroom [L]
RewriteRule ^blog$ index.php?route=blog/home [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !.*\.(ico|gif|jpg|jpeg|png|js|css)
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]
RewriteRule ^about$ https://www.example.ie/about_us/ [R,L]

You need to keep redirect rules before internal routing ones:
RewriteEngine On
RewriteBase /
RewriteRule ^about$ https://www.example.ie/about_us/ [R,L]
RewriteRule ^showroom$ index.php?route=showroom/showroom [L]
RewriteRule ^blog$ index.php?route=blog/home [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !.*\.(ico|gif|jpg|jpeg|png|js|css)
RewriteRule ^(.*)$ index.php?_route_=$1 [L,QSA]

Related

Modify code htaccess to accept parameters via URl

Modify code to accept parameters via URl. Rules to redirect URLs to www.site.com/acessorios.php tried are as follows, where .htaccess rules file is present along side with app folder.
RewriteEngine ON
RewriteBase /app/views/
##External redirect rules from here.
RewriteCond %{THE_REQUEST} \s/app/views/([^.]*\.php)\s [NC]
RewriteRule ^ /%1? [R=301,L]
##Internal rewrite rules from here.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^.]*\.php)/?$ /app/views/$1 [QSA,L]
Samples:
www.site.com/accessories.php?id=1
www.site.com/accessories.php?id=1&name=Tiago
www.site.com/accessories.php?id=1&name=Tiago&image=foto.png
Samples:
www.site.com/accessories/1
www.site.com/accessories/1/Tiago
www.site.com/accessories/1/Tiago/foto.png
This order may be different
With your shown samples and attempts please try following .htaccess rules file. Please make sure to clear your browser cache before testing your URLs.
RewriteEngine ON
RewriteBase /app/views/
##External redirect rules from here....
RewriteCond %{THE_REQUEST} \s/([^.]*)\.php\?id=(\d+)\s [NC]
RewriteRule ^ /%1/%2? [R=301,L]
RewriteCond %{THE_REQUEST} \s/([^.]*)\.php\?id=(\d+)&name=(\S+)\s [NC]
RewriteRUle ^ /%1/%2/%3? [R=301,L]
RewriteCond %{THE_REQUEST} \s/([^.]*)\.php\?id=(\d+)&name=(\S+)&image=(\S+)\s [NC]
RewriteRule ^ /%1/%2/%3/%4? [R=301,L]
##Internal rules from here onwards....
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)/([^/]*)/([^/]*)/([^/]*)/?$ /app/views/$1.php?id=$2&name=$3&image=$4 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)/([^/]*)/([^/]*)/?$ /app/views/$1.php?id=$2&name=$3 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)/([^/]*)/?$ /app/views/$1.php?id=$2 [QSA,L]

Remove the query string from url using htaccess

I need some help with htaccess. Would you be so kind to assist a little bit?
I have a URL like this
https://example.com/index.php?p=application-intelligence
[or]
https://example.com/?p=application-intelligence
Basically the index.php is passed some parameter 'home' to know which page to load i.e. home.php
So I've tried to follow your post on your blog but with not much luck.
So I'd like the final code to be
https://example.com/application-intelligence
Here's my code.
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ index.php?p=$1
Also for the
https://example.com?p=home
I'd like it to be just
https://example.com
You may use these rules:
RewriteEngine on
# handle /?p=home
RewriteCond %{THE_REQUEST} \s/+(?:index\.php)?\?p=home\s [NC]
RewriteRule ^ /? [R=301,L,NE]
# handle /?p=<something>
RewriteCond %{THE_REQUEST} \s/+(?:index\.php)?\?p=([^\s&]+) [NC]
RewriteRule ^ /%1? [R=301,L,NE]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ index.php?p=$1 [L,QSA]
This is what i have in my apache virtual host conf file:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ index.php?$1 [L,QSA]

htaccess url re-styling image url to seo friendly

I am currently using htaccess to force to use index.php file. like given below.
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?/$1 [L]
In current website it has some uploaded contents like
uploads/item/11.jpg
uploads/item/12.jpg
uploads/item/13.jpg
I wanted to re re-write it like.
uploads/item/11.jpg => uploads/item/11-itemName11whatEver.jpg
uploads/item/12.jpg => uploads/item/12-itemName12whatEver.jpg
uploads/item/13.jpg => uploads/item/13-itemName13whatEver.jpg
Can anyone help me to find RewriteCond and RewriteRule for this.
Updated
Updated htaccess
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} uploads-
RewriteRule ^uploads-([^/]+)-([0-9]+)-[^.]+\.([a-z]+)$ uploads/$1/$2.$3 [L,NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?/$1 [L]
This helps me to make the URL look like
www.store45.loc/uploads-item-11-sample-watch.jpg
RewriteCond %{REQUEST_FILENAME} uploads-
RewriteRule ^uploads-([^/]+)-([0-9]+)-[^.]+\.([a-z]+)$ uploads/$1/$2.$3 [L,NC]

Htaccess rewrite Single, or multiple $_GET parameter on LINUX base server

Below's url is I need .htaccess rewrite from ?view=home to /view/home
http://example.com/?view=home
And what if my url is quite dynamic with $_GET Parameter that have multiple $_GET?
http://example.com/?view=home&url=this&name=test&id=that
I had try few rewrite module but cant get result that I wanted.
Below is my rewrite engine :
Options +FollowSymlinks
RewriteEngine On
# specific rule
RewriteCond %{QUERY_STRING} ^([^=]+)=([^&]+)
RewriteRule ^(constant)$ /index.php?view$1 [L]
# general catch-all
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?url=$1 [L]
My current web hosting is on Linux Web Hosting, locally running my tested file is on XAMPP environment.
You can this code to redirect from ?view=home to /view/home:
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{THE_REQUEST} /\?([^=]+)=([^\s&]+) [NC]
RewriteRule ^ /%1/%2? [R=302,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)/?$ /index.php?$1=$2 [L,QSA]
# specific rule
RewriteCond %{QUERY_STRING} ^([^=]+)=([^&]+)
RewriteRule ^(constant)$ /index.php?view$1 [L]
# general catch-all
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?url=$1 [L]

Htaccess Rewrite showing 404 not found

I have this rewite rule in my htaccess file that removes index.php on the URL to just show the domain name
RewriteCond %{THE_REQUEST} /index\.php [NC]
RewriteRule ^(.*?)index\.php$ /$1 [L,R=302,NC,NE]
But it seems to show 404 not found on all other directories. For example, I have a directory called admin and if I go to www.domain.com/admin I get 404 not found
I also have this code above the RewriteCond code
RewriteCond %{REQUEST_URI} !^/admin [NC]
Here is my full htaccess file
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/admin [NC]
RewriteCond %{REQUEST_URI} !^/status [NC]
RewriteCond %{REQUEST_URI} !^/customer [NC]
RewriteCond %{THE_REQUEST} /index\.php [NC]
RewriteRule ^(.*?)index\.php$ /$1 [L,R=302,NC,NE]
# Rewrites /services to be /home.php?id=services
RewriteRule ^([a-zA-Z0-9-]+)/?$ /home.php?id=$1 [L,QSA]
#BLOG
# Rewrites /blog/this-is-a-blog-post to be /home.php?id=blog&slug=this-is-a-blog-post
RewriteRule ^([a-zA-Z0-9-]+)/([\w-]+)/?$ /home.php?id=$1&slug=$2 [L,QSA]
# Rewrites /blog/year2013/month12 to be /home.php?id=blog&year=2013&month=01
RewriteRule ^([a-zA-Z0-9-]+)/year([0-9]+)/month([0-9]+)/?$ /home.php?id=$1&year=$2&month=$3 [L,QSA]
I believe services rules is causing problem here. Change that to:
# Rewrites /services to be /home.php?id=services
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9-]+)/?$ /home.php?id=$1 [L,QSA]
Do the same for blog rule also:
#BLOG
# Rewrites /blog/this-is-a-blog-post to be /home.php?id=blog&slug=this-is-a-blog-post
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9-]+)/([\w-]+)/?$ /home.php?id=$1&slug=$2 [L,QSA]