I'm setting up a small set of rewrite rules in an htaccess file, where I want every url to go to a index.php file except for /admin which I want to redirect to admin.php. Not very familiar with mod_rewrite or regexp unfortunately.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^admin$ admin.php [L]
RewriteRule . /index.php [L]
</IfModule>
This gives me an internal server error (not saying 500). Removing or uncommenting the admin rewrite makes it work.
The conditions need to be applied to the index.php rewrite rule, otherwise it causes a redirect loop. A RewriteCond only gets applied to the immediately following RewriteRule so the rule that routes everything to index has no conditions. Try just rearranging the lines:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^admin$ admin.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Related
Got flamer script (http://provenlogic.xyz/flamer) installed and configured but start to get problem just in Opera and Chrome (in Firefox and IE works fine).
Here is my installation http://chronogym.com/flamer
The same url causes endless loop in Chrome and Opera and works fine in FF.
First question is how it could depend on browser, because I thought that redirections are driven only by server side.
Another question: when adding something like dd('test'); somewhere in controller even in FF script begins to brake connection instead of showing dumping result.
Project is placed in subdir on server: root/flamer. In root I got other project. I suggest that .htacces from that project can cause problems or conflicting with .htaccess from flamer but can't find out the exact cause.
root .htaccess
ModPagespeed off
RewriteEngine On
RewriteBase /
#Options +FollowSymlinks
############################################
## always send 404 on missing files in these folders
RewriteCond %{REQUEST_URI} !^/(_css|_js|memberarea)/
############################################
## never rewrite for existing files, directories and links
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
############################################
## rewrite everything else to index.php
RewriteRule .* index.php [L]
ErrorDocument 404 http://www.chronogym.com
RedirectPermanent /coaching.php http://chronogym.com/2-0-coaching_minceur.html
subdir .htaccess
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.chronogym.com/flamer/$ [NC]
RewriteRule ^(.*)$ http://chronogym.com/flamer$1 [R=301,L]
# Handle Front Controller...
RewriteCond %{REQUEST_URI} !^/admin
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
Your middle rule is not correct but that would conflict anyway. You need to use RewriteBase if this .htaccess file is in the flamer folder. Have your rules like this.
RewriteEngine On
RewriteBase /flamer/
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_URI} !^/admin
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
I have been using htaccess to remove rewrite certain URLs, however I am looking at something a little more complicated at the moment.
Our website blog (WordPress) used to have links like this:
/blog/postname/1387
However after redoing the website our links are now currently just
/postname
Would it be possible to redirect any uses from /blog/postname/1387 and get rid of the blog and number at the end via htaccess so it just contains the postname? At the moment I have:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteRule ^blog/(.*)/.*$ $1/
</IfModule>
Would love to hear any hints or tips, as this is not actually doing any redirecting, what am I doing wrong?
Let's just do a little cleanup:
<IfModule mod_rewrite.c>
#Turn on the RewriteEngine
RewriteEngine On
#Rewrites are all relative to /
RewriteBase /
#Explicit - If the request is for index.php, do nothing.
RewriteRule ^index\.php$ - [L]
#Conditional – Unless the file or directory specifically exists,
#If the request is for the old style blog URI, redirect to new style and stop.
#Otherwise, redirect to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^blog/(.*)/.*$ $1/ [R=301,L,QSA]
RewriteRule . /index.php [L]
</IfModule>
I tried a lot of code without results.
I'm using wordpress and the url of search results is:
http://mysite.com/search/the%20search%20query%20
I need to change it in
http://mysite.com/search/the-search-query/
Is there a way with htaccess?
This is actually my htaccess file:
# 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>
Options +FollowSymlinks -MultiViews
RewriteRule ^(.+)(\s|%20)(.+)$ /$1-$3 [R=301,QSA,L,NE]
# END WordPress
The last rewrite rule is what i trie without success
Your rule looks fine, however you have it after your routing rules. That means no matter what, that rule will never be reached because everything, including any request with a space in it, gets routed to index.php. You need to put any redirect rules before your routing rules:
Options +FollowSymlinks -MultiViews
RewriteRule ^(.+)(\s|%20)(.+)$ /$1-$3 [R=301,QSA,L,NE]
# 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'm trying to make it so that anything at /about goes to /our-story.
I think my .htaccess redirect rule is correct for this:
# 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]
The line is here:
RewriteRule ^about.*$ http://domain.com/our-story/ [R=301,L]
</IfModule>
However it doesn't seem to work. My suspicion is that this is due to Wordpress being active. I tried to put it inside the Wordpress block though, and still it doesn't work.
What do I have to do to redirect from /about to /our-story?
The rule is correct, but they need to go before the wordpress rules because you are redirecting while the wordpress rules routes everything into /index.php. Any request URI that starts with /about will end up getting routed to wordpress and thus never get redirected. Just switch the order:
RewriteRule ^about.*$ http://domain.com/our-story/ [R=301,L]
# 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>
I have a blog set up at blog.ftj.com/ACSM, it is hosted with Bluehost and their folder structures seem to be case sensitive. Is there something in the .htaccess file that I can adjust so that all possible combinations get redirected to the specific uppercase URL.
Another issue is that it seems that I need to redirect
blog.ftj.com/acsm/
with and without the forward slash.
Here is my current .htaccess file
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /ACSM/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /ACSM/index.php [L]
</IfModule>
# END WordPress
Please submit the full change if you would.
You need to place the following .htaccess in the root dir to rewrite all requests to /ACSM into /acsm
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/acsm$ [NC]
RewriteRule ^(.*)$ /ACSM [L]
RewriteCond %{REQUEST_URI} ^/acsm/(.*)$ [NC]
RewriteRule ^acsm/(.*)$ /ACSM/$1 [L]
</IfModule>
Sorry for delays, have not got an Apache at hands....