I've a website built on apache and I've to migrate it into IIS. I don't know nothing about web.config, but I've a very simple .htaccess to translate.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
Anyone can help me?
Thanks a lot
Bye
Related
I am a beginner and I coded a hataccess that works as I want on my site but can not redirect to an external site like facebook twitter or linked. Can you help me please. Thank you.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
I m studid !
The .htaccess works fine, the problem was my links, the protocol was missing !!!!
The old URLs are like this:
http://mywebsite.com/index.php?mode=thread&id=284607
The new URLs would be:
http://mywebsite.com/threads/284607
As you can see, I want to grab the ID # from the old dynamic URLs and point them to the new pretty URLs.
I've tried finding the solution here and elsewhere, but keep having problems removing the "mode=thread" part from the redirect.
Thanks for your help!
Update: Here's some other code that is already in the .htaccess file.
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^(data/|js/|styles/|install/|favicon\.ico|crossdomain\.xml|robots\.txt) - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
After a lot of Googling, I found this to work:
RewriteCond %{QUERY_STRING} (^|\?)mode=thread&id=([0-9]+)($|&)
RewriteRule ^index\.php$ http://mywebsite.com/threads/%2/? [R=301,L]
In your .htaccess file:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^mode=thread
RewriteCond %{QUERY_STRING} &id=([0-9]+)
RewriteRule ^index\.php$ /threads/%1? [L,R=301]
I am not experienced with htaccess... But I am authoring a site on which I am using a simple redirect. I basically just copied the first htaccess that I found and it works fine, but I am curious if I am using it properly and/or if it is responsible for some problems I am having with the site.
This is my file..
RewriteEngine On
Exclude some directories from URI rewriting
RewriteRule ^(dir1|dir2|dir3) - [L]
RewriteRule ^\.htaccess$ - [F]
RewriteCond %{REQUEST_URI} =""
RewriteRule ^.*$ /src/index.php [NC,L]
RewriteCond %{REQUEST_URI} !^/src/.*$
RewriteRule ^(.*)$ /src/$1
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^.*$ - [NC,L]
RewriteRule ^src/.*$ /src/index.php [NC,L]
The index.php (as you can tell) lives in /src), as does most pf the site.
One problem I am having is that accessing some of the includes results in pulling back the index.php!
Any advice, or directions to some tuts or articles on htaccess would be GREATLY appreciated.
Thanks
Have to say that the lot of the code in here looks redundant. Replace your code with this:
RewriteEngine On
RewriteRule ^\.htaccess$ - [F]
RewriteCond %{REQUEST_URI} ^/(dir1|dir2|dir3) [OR]
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
RewriteCond %{REQUEST_URI} !^/src/.*$
RewriteRule ^(.*)$ /src/$1 [L]
RewriteRule ^src/.*$ /src/index.php [NC,L]
Also when you say that ccessing some of the includes results in pulling back the index.php! I hope you are just including them like:
include('path/to/somefile.php');
That won't go through .htaccess since this inclusion is transparent to Apache.
Try combining a few of the rules:
RewriteEngine On
# Exclude some directories from URI rewriting
RewriteRule ^(dir1|dir2|dir3) - [L]
# block access to the htaccess file
RewriteRule ^\.htaccess$ - [F,L]
# route "/" requests to index.php
RewriteRule ^$ /src/index.php [L]
# route requests that exists in /src/ to /src/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/src%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}/src%{REQUEST_URI} -d
RewriteRule ^(.*)$ /src/$1 [L]
# route everything else to /src/index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /src/index.php [L]
My .htaccess file alows access to real files & folders on the server. For anything else, it will redirect to /index.php, except when the app folder is specified in which case it will redirect to /app/index.php. I want to add a second folder named appbeta which will redirect to /appbeta/index.php. How should I modify my .htaccess to add this additional exception?
SetEnv APPLICATION_ENV development
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(?!app)(.+)$ /index.php?u=$1 [NC,QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^app(.+)$ /app/index.php?u=$1 [NC,QSA,L]
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
I am not exactly sure what the following rewrite does:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(?!app)(.+)$ /index.php?u=$1 [NC,QSA,L]
However, if your current .htaccess is working as you want, I would try the following which puts a rewrite for /appbeta right before the rewrite for /app:
SetEnv APPLICATION_ENV development
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(?!app)(.+)$ /index.php?u=$1 [NC,QSA,L]
# rewrite /addbeta to /appbeta/index.php ...
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^appbeta(.*)$ /appbeta/index.php?u=$1 [NC,QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^app(.+)$ /app/index.php?u=$1 [NC,QSA,L]
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
note: no new question started as mentioned in comments, fix above (change ^appbeta(.+)$ to ^appbeta(.*)$)
can someone help me with the code to use only one file.
e.g.
domain.com/
domain.com/hello/world/
domain.com/help.php
all the above should load
domain.com/index.php
I have done this at home, but i cnt remember it and i dont have access to that code.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) index.php
i think the following is something that i remember but it aint working.
check if rewrite module is working
cat /etc/apache2/mods-available/rewrite.load
LoadModule rewrite_module /usr/lib/apache2/modules/mod_rewrite.so
this one is from zend framework, I think should be better than general used one
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]