I am using WAMP and I want to remove index.php from my url and I used this code:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# Removes index.php from ExpressionEngine URLs
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteCond %{REQUEST_URI} !/system/.* [NC]
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]
# Directs all EE web requests through the site index file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
</IfModule>
Then I had to change two lines as I moved my files to sub-directory OOP-Project from:
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]
and
RewriteRule ^(.*)$ /index.php/$1 [L]
to:
RewriteRule (.*?)index\.php/*(.*) OOP-Project/$1$2 [R=301,NE,L]
and
RewriteRule ^(.*)$ OOP-Project/index.php/$1 [L]
But, the changes are not taking effect although first time it worked! I tried adding syntax error and it showed the error. Surprisingly, when I moved my files to another folder say OOP-Project-1, it worked. I did a lot of research and found this Changes to RewriteRule in .htaccess not taking effect But it didn't address the problem correctly.
Hope someone helps!
Related
I know that there are too many questions and answers about this so i have to apologize in advanced but nothing works for me.
I lunched my website in Godaddy/Linux Hosting and trying to apply a rewrite for my urls. What it looks like now is
https://www.mywebsite.com/tours/tour_id=15
and i would like it ot be
https://www.mywebsite.com/tour/15 or even better insted of the ID to GET the title from the sql (which if is not possible through htaccess i can do it with php) My Own Title https://www.mywebsite.com/tour/My Own Title
I am really new in htaccess, below is what is already written in the file
# Redirects to https
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{HTTP_HOST} ^(www\.)?mywebsite\.com
RewriteRule ^(.*)$ https://www.mywebsite.com/$1 [R=301,L]
RewriteEngine On
RewriteBase /
# Removes index.php from ExpressionEngine URLs
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteCond %{REQUEST_URI} !/system/.* [NC]
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]
# Directs all EE web requests through the site index file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
# Remove trailing slash in the end
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
I would be grateful for any help
Add to top of .htaccess this rewrite rule:
RewriteEngine On
RewriteRule ^tour\/\d+$ /tours/tour_id=$1 [L]
after a long search I finally created an htaccess file with the rules i need. In the local host everything works fine but on the GoDaddy hosting only the half rules are working... does anyone had the same problem or know how to solve it? Thank you
# THIS IS NOT WORKING / Returns a page not found error
RewriteEngine On
RewriteRule ^/?customize/?$ all_poi.php
RewriteRule ^/?santorini/?$ santorini.php
RewriteRule ^/?aboutus/?$ aboutus.php
RewriteRule ^/??tours/?$ all_tours.php
RewriteRule ^/?tours/([0-9]+) tours.php?tour_id=$1& [L]
# Redirects to https / WORKING
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{HTTP_HOST} ^(www\.)?mywebsite\.com
RewriteRule ^(.*)$ https://www.mywebsite.com/$1 [R=301,L]
#remove trailing slash / WORKING
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301] # <- for test, for prod use [L,R=301]
# Removes index.php from ExpressionEngine URLs / WORKING
RewriteEngine On
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteCond %{REQUEST_URI} !/system/.* [NC]
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]
I would like redirect http://example.com/index.php?a=music to http://example.com/music (where the number is a variable/dynamic). My site is http : / / example . com
I added the following line to my mod-rewrite rules in my .htaccess file:
RewriteRule ^index\.php$/?/a/=(.*)$ http://example.com/index.php?a=$1 [L,R=301]
However, it doesn't seem to work. I know I'm doing something wrong, I'm just not sure how to fix it. Any help is appreciated.
Best,
Jeff
Edited:
Thanks Tom,
This is what I have:
Rewritecond %{HTTP_HOST} ^example\.com
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# Removes index.php from ExpressionEngine URLs
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteCond %{REQUEST_URI} !/system/.* [NC]
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]
# Directs all EE web requests through the site index file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
This should work:
RewriteRule ^(.*)$ /index.php?a=$1 [L]
i made a website by expressionengine, in the htaccess i need to remove the index.php and also add www to none www url's.
here is my current .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# Add www to url
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
# Directs all EE web requests through the site index file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
# Removes index.php from ExpressionEngine URLs
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteCond %{REQUEST_URI} !/system/.* [NC]
RewriteRule (.*?)/index\.php/*(.*) /$1$2 [R=301,NE,L]
</IfModule>
but the above code has some problems, it works when the url has the www itself and there is no index.php anywhere and everything is fine, but when i remove the www from the url to test the "add www" part it does not work any more and the url damages lik this:
http://www.example.com/index.php?/segment1/segment2/
an index.php comes up. i don know what to do, any help will be appriciated
Try this..
RewriteEngine On
#Redirect non-www to www
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
it will remove index.php from the URL and add www as a prefix.
The www redirect probably doesn't work because there's no wildcard, keep it simple and specify your domain:
# Redirect to www
# -------------------
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
I expect you have the removal and addition of index.php the wrong way around, I redirect it first if specified in the URL, then add it in hidden:
# Redirect specific index.php requests in URL
# ------------------------------
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteCond %{REQUEST_URI} !/system/.* [NC]
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,L]
# Directs all EE web requests through the site index file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
Also try with and without the ? on this line, depending on the server setup, this might not be needed:
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
or
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
I want to remove the default index.php that auto comes with Codeigniter.
I've been able to remove that with this code
RewriteRule ^(.*)$ index.php/$1 [L]
example.com/index.php/blog can now be accessed by example.com/blog
I later wanted to prefix the URL with a www i.e example.com/blog should redirect to www.example.com/blog with these rewrite rules
RewriteCond %{HTTP_HOST} ^(?!www\.)(.+) [NC]
RewriteRule ^(.*) http://www.%1/$1 [R=301,NE,L]
After adding this code above to the end of my .htaccess file, it began to misbehave.
If I enter www.example.com/blog into a URL bar it works fine but if I enter example.com/blog it redirects to www.example.com/index.php/blog
What I'm I doing wrong?
I want example.com/blog to redirect to www.example.com/blog
Note: I am using the Codeigniter framework.
Added: This code is just on top of the previous ones I have up. Maybe this is it's problem please HELP!!!
RewriteCond $1 !^{index\.php|[assests/images/themes/fonts/style/scripts/js/install]|robot\.txt|favicon\.ico}
Try this:
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ example.com/$1 [L,R=301]
After much tricks and following the post given by #Tpojka I was able to come up with this
RewriteEngine On
RewriteBase /
# Removes trailing slashes (prevents SEO duplicate content issues)
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ $1 [L,R=301]
# no www -> www
RewriteCond %{HTTP_HOST} ^(?!www\.)(.+) [NC]
RewriteRule ^(.*) http://www.%1/$1 [R=301,NE,L]
# Checks to see if the user is attempting to access a valid file,
# such as an image or css document, if this isn't true it sends the
# request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
This guy was my problem
RewriteCond $1 !^{index\.php|[assests/images/themes/fonts/style/scripts/js/install]|robot\.txt|favicon\.ico}
I would need help on how to exclude folders and some files like robot.txt file like I tried in the malfunctioning line.
This is the complete .htaccess file which I use personally:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>