Vasu Kireeti
Vasu Kireeti

Reputation: 31

htaccess rewrite rules not working

I have created a subdomain of a site. The subdomain is pointed to a folder on the root.

For some reasons, the following rewrite rules are not working. Two segment urls are working. One is not working and more than two is not working. Please see the urls below.

When i have two segments created dynamically, they are not working.

.

Options +FollowSymlinks
RewriteEngine   On
RewriteBase     /
RewriteCond     %{HTTPS} on
RewriteRule     (.*) http://%{HTTP_HOST}%{REQUEST_URI}

#FOR REPLACING .HTML EXTENSION (WORKS FINE)
RewriteCond     %{REQUEST_FILENAME}     !-f
RewriteCond     %{REQUEST_FILENAME}     !-d
RewriteCond     %{REQUEST_FILENAME}\.html -f
RewriteRule     ^(.*)$ $1.html

#FOR REPLACING .PHP EXTENSION (NOT WORKING)
RewriteRule     ^([a-zA-Z0-9_-]+)$ $1.php
RewriteRule     ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)$ $1.php

Let me know if you don't understand this question.

Upvotes: 3

Views: 676

Answers (1)

Jon Lin
Jon Lin

Reputation: 143856

Like Michael Berkowsk suggests, you probably want to add L flags to the end of your rules so that you end rewriting when the rule has been applied. Other than that, the 2 segment rule that you have only uses the first as a backreference, I assume you want to use both? Try changing your rules to look like this:

Options +FollowSymlinks
RewriteEngine   On
RewriteBase     /

# the HTTP redirect
RewriteCond     %{HTTPS} on
RewriteRule     (.*) http://%{HTTP_HOST}%{REQUEST_URI} [L,R]

#FOR REPLACING .HTML EXTENSION (WORKS FINE)
RewriteCond     %{REQUEST_FILENAME}     !-f
RewriteCond     %{REQUEST_FILENAME}     !-d
RewriteCond     %{REQUEST_FILENAME}\.html -f
RewriteRule     ^(.*)$ $1.html [L]

#FOR REPLACING .PHP EXTENSION 
RewriteCond     %{REQUEST_FILENAME}     !-f
RewriteCond     %{REQUEST_FILENAME}     !-d
RewriteCond     %{REQUEST_FILENAME}\.php -f
RewriteRule     ^(.*)$ $1.php [L]

RewriteCond     %{REQUEST_FILENAME}     !-f
RewriteCond     %{REQUEST_FILENAME}     !-d
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)$ location.php?li_id=$1&lid=$2 [L]

Upvotes: 2

Related Questions