This question already has answers here:
Url rewriting mod_rewrite
(3 answers)
Closed 6 years ago.
Im pretty new to Apache's mod_rewrite and I'm trying to change how my URLs are displayed in the address bar. For instance I want
www.example.com/index.php
to be
www.example.com/home
and
www.example.com/products.php
to be
www.example.com/products
and so forth. So far I have this in mind but it's not working
RewriteRule ^home$ /index.php [L]
You need to do the following:
Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) http://www.example.com/home/$1 [R=301]
Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) http://www.example.com/products/$1 [R=301,L]
You can either put this on httpd.conf in apache or in .htaccess file.
L means - Last - stop processing rules
You can try this. Edit the .htaccess file contents as:
Options +FollowSymLinks
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
</IfModule>
This will redirect an url like this: example.com/any_path.php to example.com/any_path. To be precise, you are removing the .php extension from any PHP file.
Note:
For specific url, replace ([^\.]+) in the RewriteRule with the text.
Specify a correct path for RewriteBase in case you are using a subdirectory.
mod_rewrite should be turned on for your server system. Google a bit for turning on mod_rewrite in your system.
Related
I have been trying for the past few days to get a Godaddy hosted server to hide the question mark and the variable name in the url automatically (ie. mysite.com/?id=5 >>> mysite.com/5) using Rewrite Rules in the .htaccess file.
My current .htaccess file looks like this:
RewriteEngine On
Options -MultiViews
RewriteBase /
RewriteRule ^/(.*)$ /index.php?id=$1 [P]
Am I doing something wrong or is it the Godaddy servers? Thank you in advance!
Try adding the following into your .htaccess file.
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^index/(\d+)*$ ./index.php?id=$1
You can learn more about clean urls here: http://www.desiquintans.com/cleanurls
Hi So I am trying to remove includes/pagesfrom a url that looks like http://localhost:8888/london/includes/pages/soho-london-guide/ For local dev. I am using MAMP and I've enabled mod_rewrite too.
So far I've been trying to use different techniques and here is a list of what I've been using (trying to make it work :((( )
RewriteEngine ON
RewriteRule ^includes/pages/(.*)$ $1 [L,QSA]
Also
RewriteEngine on
RewriteBase /
RewriteRule ^/includes/pages/(.+)$ /$1 [L,QSA]
Very very new to .htaccess and regex syntax so any help would be appreciated.
Have this rule in your site root .htaccess:
RewriteEngine on
RewriteBase /
RewriteRule ^([\w-]+)/(?!includes/pages/)(.+)$ $1/includes/pages/$2 [L,NC]
I am working for someone who runs a webshop. Now the webshop runs on Opencart software, and fortunately they support SEO Url rewriting. I have been trying to get this working for the last 2 hours and havent been able to get it right. I have done the following to the .htaccess file.
# 1.To use URL Alias you need to be running apache with mod_rewrite enabled.
# 2. In your opencart directory rename htaccess.txt to .htaccess.
# For any support issues please visit: http://www.opencart.com
Options +FollowSymlinks
# Prevent Directoy listing
Options -Indexes
# Prevent Direct Access to files
<FilesMatch ".(tpl|ini|log)">
Order deny,allow
Deny from all
</FilesMatch>
# SEO URL Settings
RewriteEngine On
# If your opencart installation does not run on the main web folder make sure you folder it does run in ie. / becomes /shop/
RewriteBase /opencart/
RewriteRule ^sitemap.xml$ index.php?route=feed/google_sitemap [L]
RewriteRule ^googlebase.xml$ index.php?route=feed/google_base [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]
Additionally i have enabled SEO rewriting on opencart and given all products/categories etc. a SEO name.
Now the .htaccess file is located in: public_html/opencart/ so i have changed the RewriteBase from / to /opencart/
Still i get the following errors:
Not Found
The requested URL /aquaria/adm-aquaria was not found on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
Does anyone have a solution for me?
To give you an example i want the following link: http://aquadeco.eu/index.php?route=product/category&path=94_291 to look like this: http://aquadeco.eu/aquaria/adm-aquaria
You don't have to put this
RewriteBase /opencart/
If your url are like this yourDomain.com/opencart/index.... Then
you will have to put RewriteBase /opencart/
end if; :)
with your url you don't have to put RewriteBase /opencart/
only /
Regards
Ok, wow i just found out i have been stupid the whole time. I had 2 .htaccess files. One which was the original without the right rewrite rules and 1 in my /opencart/ folder which had the right rewrite rules. What i did now is put the right rewrite rules into the .htaccess file in my root folder and it fixed the problem!! :D
You put your site in sub directory so you have to make following changes
RewriteBase /opencart/ change to RewriteBase /
and
RewriteRule ^([^?]*) index.php?route=$1 [L,QSA] change to
RewriteRule ^([^?]*) /opencart/index.php?route=$1 [L,QSA]
This question already has answers here:
How to remove "index.php" in codeigniter's path
(27 answers)
Closed 7 years ago.
I am using codeigniter 3.0 and xampp. When I try to reference a page in xampp with codeigniter it goes to the xampp index page.
Here is my .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
# !IMPORTANT! Set your RewriteBase here and don't forget trailing and leading
# slashes.
# If your page resides at
# http://www.example.com/mypage/test1
# then use
# RewriteBase /mypage/test1/
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin
ErrorDocument 404 /index.php
</IfModule>
You could try http://localhost/project/index.php/route-name But if your trying to do it without index.php try my example below.
Disclaimer: I do not know what versions of system/server you are running so could show a different result this is just example to help you along.
Create a file in main directory called .htaccess Do not touch the htaccess in application folder
Options +FollowSymLinks
Options -Indexes
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
I use the same htaccess on my live server no issues Hosting Provider http://www.arvixe.com/9875-0-1-370.html
Remove index.php from config.php $config['index_page'] = '';
Also if you have any links that include index.php remove that also example.
base_url('index.php/route-name');
Change To
base_url('route-name');
Or
site_url('index.php/route-name');
Change To
site_url('route-name');
If you are still having issue check your routes.php make sure you have configured your routes in application/config/route.php $route['name'] = "route-name/index"; check your name of controller.
In codeigniter 3.0 you also need to have the controller capitalized. example Welcome.php
If that does not work I found this https://github.com/riwakawebsitedesigns/htaccess_for_codeigniter has about 5 examples you could try depending on your server / OS-system
I am trying to create mod_rewrite rules to redirect the following url in my wordpress site:
www.mywebsite.com/pg/2/row/20/filter/all/filtercity/foo,bar
to
www.mywebsite.com/detail?pg=2&row=20&filter=all&filtercity=foo,bar
My problem is that wordpress included the following rules in the .htaccess:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
I tried the following RewriteRule and it kind of works if I comment the last RewrireRule from Wordpress.
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#RewriteRule . /index.php [L]]
RewriteRule ^pg/([a-zA-Z0-9]+)/?$ ?pg=$2 [R]
</IfModule>
# END WordPress
The above works only for urls like
www.mywebsite.com/pg/2 => www.mywebsite.com?pg=2
A few questions:
1 - how can I configure .htaccess to process the url only when it finds the following keys
/pg and/or /row and/or /filter and/or /filtercity
for all other urls, it should execute the standard Wordpress RewriteRule . /index.php
2 - also the url can have all of the keys or only a few of them. For example:
/pg/2/row/20
/row/20/filter/all
how can I configure the .htaccess to process all the different combinations of keys?
3 - when I tried replacing
RewriteRule ^pg/([a-zA-Z0-9]+)/?$ ?pg=$2 [R]
with
RewriteRule ^pg/([a-zA-Z0-9]+)/?$ detail?pg=$1 [R]
I got a 404 error from the server. Not sure why. Any ideas?
Thank you.
EDIT 1:
I tried adding [L] to the end of my RewriteRule (see below)
RewriteRule ^pg/([a-zA-Z0-9]+)/?$ ?pg=$1 [R,L]
and moving the standard Wordpress rewrite rule to the next line
RewriteRule . /index.php [L]
After doing that I no longer get server 404 error. However the CSS files stop loading.
1 - how can I configure .htaccess to process the url only when it
finds the following keys
/pg and/or /row and/or /filter and/or /filtercity
Read this Rewrite URL with .htaccess for multiple parameters
The above answer helps you to solve your problem when have a standard url format.
2 - also the url can have all of the keys or only a few of them. For
example:
/pg/2/row/20
/row/20/filter/all
You are trying to do something out of URL semantics. When you try to access a resource, the path should be same every time. You can pass pg/0/ if you are on the starting page. But who can stop you from going out of URL semantics? :) In that case you have to have all the combinations as rules in your .htaccess. Follow the above solution, with all URL combinations it will work.
My Suggestions:
Don't Struggle with .htaccess if you are not familiar and your need is only URL rewrite (it is powerful though)
Pass everything to the index file and parse in your code, for your case have a look at this page http://codex.wordpress.org/Query_Overview