2

This is my .htaccess file:

Options +FollowSymLinks
Options -Multiviews

RewriteEngine On
RewriteBase /website/

RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .? - [S=20]

RewriteRule ^(.*)$ $1.php 
RewriteRule ^([a-z0-9_-]+)/([a-z0-9_-]+)(/)?$ index.php?occ=$1&cat=$2

now these 2 lines together are not working for example:

if I were to go to contact.php, I would type in my url: localhost/website/contact and it would work

however if I want to go to location/website/index.php?occ=occasion&cat=category by typing this in my url: localhost/website/occasion/category it will only work if I remove the first rewrite rule

but then I cant go to localhost/website/contact anymore

what am I missing here?

2 Answers 2

5

Your Problem is your order.

/website/occasion/category first gets rewritten to be /website/occasion/category.php, which then fails to match the second rule.

RewriteRule ^([a-z0-9_-]+)/([a-z0-9_-]+)(/)?$ index.php?occ=$1&cat=$2 [L]
RewriteRule ^(.*)$ $1.php

Changing the order and adding the [L] parameter to the rule (stop executing followup rules after succesful execution) should fix the issue.

Sign up to request clarification or add additional context in comments.

Comments

0
RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^site_1/(.*)$ site_1/index.php?/$1 [L]
RewriteRule ^site_2/(.*)$ site_2/index.php?/$1 [L]

as in sites you won't have 1000s of sites you can declare your desire link and folder name e.g. if your structure is

/home/site1, /home/site2

and links will be like http://yourdomain.com/medical & http://yourdomain.com/entertainment

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.