I use .htaccess rewrite rules to redirect urls with the extension .html to .php.
These are my current rewrite rules:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)\.html$ a/$1.php [NC]
How do I get these to work on IIS6?
Apache (which is the web server in XAMPP) .htaccess (mod_rewrite) rules won't work on IIS6. You need to install a third party rewriter such as HeliconTech's ISAPI_Rewrite to achieve this.
IIS7+ supports rewriting out of the box but the format is different.
Related
Is it possible to exclude the .php from URL?
Currently i got this in my .htaccess to remove php from urls:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
But whenever i try to do
dashboard?test=lol
It doesn't work, but if i do
dashboard.php?test=lol
then it does work.
I've seen other sites being able to do it without the .php in url... so how?
Thanks.
Have you restarted the webserver?
You also need to enable AllowOverride in Apache configuration. Something similar to this:
AllowOverride All
With your shown samples, try following. Please make sure to clear your browser cache before testing of URLs.
RewriteEngine ON
RewriteCond %{THE_REQUEST} \s/([^.]*)\.php\?(\S+)\s [NC]
RewriteRule ^ /%1?%2 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)/?$ $1.php [QSA,L]
Just add this line in your site root .htaccess to enable content negotiation:
Options +MultiViews
Option MultiViews (see http://httpd.apache.org/docs/2.4/content-negotiation.html) is used by Apache's content negotiation module that runs before mod_rewrite and makes Apache server match extensions of files. So if /file is the URL then Apache will serve /file.html.
I have an existing site that uses ISAPI Rewrite by way of the .htaccess file. I am moving to a new host also on a Windows server and have been told that my rules must be loaded to the web.config file.
So the old rules looked like this:
RewriteBase /
RewriteMap mapfileNews txt:mapfile/mapfileNews.txt
RewriteCond %{QUERY_STRING} ^ArticleID=[^&]+&n=(.+)
RewriteRule ^pages/ndetail\.asp$ news/%1? [NC,R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^news/([^/]+)$ pages/ndetail.asp?
ArticleID=${mapfileNews:$1}&n=$1 [NC,L]
So what the rule is doing is opening the mapfileNews.txt file, grabbing the ID number and mapping it to an article name. Like:
http://www.website.com/pages/ndetail.asp?ArticleID=7
being rewritten to something like
http://www.website.com/news/article-name
I have no idea how to convert this over so it works in my web.config file.
And please excuse me for my noobness. I'm not tecchy at all :(
I have problems using htaccess in WAMP. I need to do the following:
1) redirect URLs like http://localhost/movie_questions/some_number/... to the file http://localhost/movie_questions.php
2) redirect URLs like http://localhost/movie_quiz/some_number/... to the file http://localhost/movie_quiz.php.
3) It's preferable that URLs in rewrite url rules be relative, because I later plan migrating to an Internet server.
Directories 'movie_questions' and 'movie_quiz' do not exist on my server.
Here is my code:
RewriteEngine On
RewriteRule /movie_questions/(.*) /movie_questions.php
RewriteRule /movie_quiz/(.*) /movie_quiz.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
Instead of redirecting, I get 404.
You need to remove the leading slash from your RewriteRule's pattern
RewriteEngine on
RewriteRule ^movie_question/(.*)$ /movie_question.php [L]
RewriteRule ^movie_quiz/(.*)$ /movie_quiz.php [L]
I've been trying to solve a problem for the past few hours. I am desperate for help!
I have two domains:
rd1.example.com/drupal
rd2.example.com
I have a drupal installation in rd1.example.com/drupal/
Further, I started creating content on drupal in a url alias: rd1.example.com/drupal/rd2/
What I want to do is used the second website to point to that specific content within my drupal installation:
rd2.example.com -> rd1.example.com/drupal/rd2/
I don't want it to be a redirect but an internal hidden redirect. The user will think that they are on rd2.example.com.
I've switched rd2.example.com to point to the directory where drupal is installed. I've been trying to edit the rewriterules on drupal's .htaccess but with no luck. Any help is greatly appreciated. Here is my rules so far:
#Existing settings
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTP_HOST} !^rd2\.example\.com [NC]
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^ index.php [L]
#New rules to accomodate for rd2.example.com
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTP_HOST} ^rd2\.example\.com$ [NC]
RewriteCond %{DOCUMENT_ROOT}/rd2%{REQUEST_URI} -f
RewriteRule .* /rd2/$0 [L]
Drupal relies on the server variables to process its request. That means when you internally rewrite to /rd2/$0, drupal doesn't know what to do with that. You'll need to reverse proxy *from the rd2` subdomain instead. So leave drupal the way it is, then on the rd2.example.com document root, add:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^rd2 [NC]
RewriteRule ^(.*)$ http://rd1.example.com/drupal/rd2/$1 [L,P]
This will only work if you have mod_proxy loaded on your server, otherwise nothing will happen. Mod_proxy can only be turned on through your server's config. You could also setup the reverse proxy from the vhost config for the rd2 subdomain:
ProxyPass / http://rd1.example.com/drupal/rd2/
Beside of proxy, you may also consider to use a symbolic link that made by a shell command like so:
ln -s /path/to/rd1 /path/to/drupal/rd2
More details is explained in Multi-site - Sharing the same code base
I am using URL Rewriting in .htaccess file my problem is this in root folder I have index.php file and I am redirect to en/home/ folder but redirection is not working when I use this .htaccess code.
RewriteRule ^([^/]*+)$ en/peoples/globalCardDetail.php?p=$1
Rewriting is working fine like this http://www.domain.com/atiq ur rehman. But when I access my domain http://www.domain.com this is redirecting to this page en/peoples/globalCardDetail.php.
You need to change your regular expression from ^([^/]*+)$ to ^([^/]+)$.
Also, you may want to add some conditions:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)$ en/peoples/globalCardDetail.php?p=$1 [L]