I added some bad code to my .htaccess file, and then my site would not even load. So I went back to a previous version that was working, but the site will still not load, I don't know if this is something to do with caching ( I emptied it by the way ) but I would like to be able to test my site again. But current browser will not go to that site. Tried the site on different computer and it is now working.
Options +FollowSymLinks -MultiViews
rewriteengine on
RewriteBase /
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]
RewriteRule ^blog/(.*)$ blog.php?article=$1 [QSA,L]
is the current .htaccess.
Options +FollowSymLinks -MultiViews
rewriteengine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php [NC,L]
## remove ugly part of url for blog.php
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]
RewriteRule ^blog/(.*)$ blog.php?article=$1 [QSA,L]
this is the one that broke it
Try uploading an empty htaccess file. The site should be work properly. Then keep adding your lines 1 by 1 until you find out which of them is causing the problem.
you might also want to check if you accidentally uploaded your htaccess file in another folder.
Related
I am very new to .htaccess files and may have done mine wrong. I have been gathering snippets of code trying to get done what I want.
This is what I have in my file so far
I read this should be in your .htaccess file
Options +MultiViews
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
This was added to force a redirect from HTTP to HTTPS
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
This was added to remove .php at the end of all the files
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
This was added to remove the showing of /index when the home link was pressed
RewriteCond %{THE_REQUEST} ^.*\/index?\ HTTP/
RewriteRule ^(.*)index\.php?$ "/$1" [R=301,L]
I have tried a lot of ideas I found on both here and other sites from Google. I have had no luck hiding the GET request.
Currently, the URL looks like https://mysite.ca/event?id=123
What I would like it to look like is either https://mysite.ca/event/123
This is hosted on Godaddy and it is just a plain PHP site if that makes any difference.
Any ideas would be great!
First of all Options +MultiViews already removes .php extension so you don't need:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
About your problem try this Rule:
RewriteRule ^event/([0-9]+)?$ event?id=$1 [NC]
Which changes url from example.com/event/<number> to example.com/event?id=<number>
Although, if your site makes infinite redirects then you should change it to:
RewriteRule ^events/([0-9]+)?$ event?id=$1 [NC]
This happens if you have some includes/headers that redirect back to event and creates infinite loop.
I have an issue with new installed centos web panel where I am using below htaccess code to redirect to index.php if file not exists where if estate.php exists then it goes directly to estate.php and if i use estate without .php then it goes to index.php.
This code below works anywhere but not on CWP (centos web panel) and the problem is that it still works for the files that don't exist at all but if file estate.php exist and in url i use estate without .php it goes to esate.php and ignors to go to index.php.
so the question is that is there any way to force it to go to index.php even if file exists but if i use estate.php then it should go directly to estate.php.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^?]*)$ /index.php?path=$1 [NC,L,QSA]
</IfModule>
You need to disable the Multiviews
Try adding the following line in your htaccess above RewriteEngine directive :
Options -Multiviews
I'm trying to remove the ".php" extension from the URLs of a site using this code (which I admit I copy/pasted from other questions here) in the .htaccess file:
RewriteEngine on
Options +FollowSymLinks
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
Other lines of the .htaccess file do work, for instance, I have an error redirect and:
RewriteCond %{HTTP_HOST} ^www\.domain\.com$ [NC]
RewriteRule ^(.*)$ http://domain.com/$1 [R=301,L]
So, I know the .htaccess file is in service in general.
I don't know what could go wrong in this area, so I'm not sure where to begin troubleshooting. Does anyone have pointers?
Thanks in advance.
Given that your domain account is /home/youraccount/public_html, your .htaccess would be inside the public_html folder with the following content:
Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteBase /
# First we redirect the www to non-www
RewriteCond %{HTTP_HOST} ^www\.domain\.com$ [NC]
RewriteRule ^/?(.*)$ http://domain.com/$1 [R=301,L]
# now we redirect phpless URLs internally to the php
# if folder does not exist
RewriteCond %{REQUEST_FILENAME} !-d
# but the file exists and ends with .php
RewriteCond %{REQUEST_FILENAME}\.php -f
# redirect to name.php
RewriteRule ^([^/]+)/?$ $1.php [L]
NOTE: If you have more rules this may conflict so I would have to look at the rest of your rule but basically the above should work as expected.
You will be able to access both:
domain.com/index
and
domain.com/index/
And it would redirect to your file index.php.
I have a site that needs to exist in a subfolder
example.com/site
But i'm trying to use the .htaccess to remove any links that contain www (to make sure codeigniter csrf doesn't throw errors), so i've added
RewriteCond %{HTTP_HOST} ^(www\.example\.com)?$
RewriteRule ^(.*)$ http://example.com/site/$1 [R=301,L]
This works well when there is a page identifier specified, so
www.example.com/site/book rewrites to example.com/site/book
But when there is no page identifier specified I get a 404
www.example.com/site rewrites to example.com/site//usr/local/pem/vhosts/103480/webspace/httpdocs/new
I was wondering if anybody could point me in the right direction?
This is my full .htaccess
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.example\.com)?$
RewriteRule ^(.*)$ http://example.com/site/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
You may try this instead:
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteCond %{REQUEST_URI} ^/(.*) [NC]
RewriteRule .* http://example.com/%1 [R=301,L]
Maybe, you're just missing a RewriteBase
Depending on where the .htaccess file is, try either
RewriteBase /
or
RewriteBase /site
Never test with 301 enabled, see this answer
Tips for debugging .htaccess rewrite rules
for details.
I have this .htaccess file which simply reroute URL from primary link ex- http://www.mywebsitename.com/somepage.php?id=some_id to http://www.mywebsitename.com/somepage/some_id
Here is the code for that-
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} !^www.ashurocks.in$
RewriteRule ^(.*)$ http://www.ashurocks.in/$1 [R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^user/([a-zA-Z0-9]+)$ /user.php?u=$1 [QSA]
RewriteRule ^group/([a-zA-Z0-9]+)$ /group.php?id=$1 [QSA]
RewriteRule ^article/([a-zA-Z0-9]+)$ /article.php?id=$1 [QSA]
It was working properly and I was able to get the content. But now, It's not working. Whenever I visit the URL http://www.mywebsitename.com/somepage/some_id, it does not redirect me to http://www.mywebsitename.com/somepage.php?id=some_id .
Is there something wrong with this .htaccess file code?
OK I got it.
I simply used Options +FollowSymLinks -MultiViews before the line RewriteEngine on and it solved my problem