1

My mission is to achieve

http://localhost/projectname/media/video

from

http://localhost/projectname/index.php?m=media&cmd=video

and also

http://localhost/projectname/home

http://localhost/projectname/index.php?m=home

Below the files helps to achieve my mission

RewriteRule ^([^/]*)$ /projectname/index.php?m=$1 
RewriteRule ^([^/]*)/([^/]*)$ /projectname/index.php?m=$1&cmd=$2 

the thing is that any external files such as javascript and css would not be taken into play.

i know my alternative is to put this is htaccess

RewriteRule ^([^/]*)/cmd/([^/]*)$ /projectname/index.php?m=$1&cmd=$2 

which enables http://localhost/projectname/media/cmd/video

I would like to make it without the CMD. Any suggestions?

2 Answers 2

2

Change your rules to this:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)/([^/]*)/?$ projectname/index.php?m=$1&cmd=$2 [L,QSA]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)/?$ projectname/index.php?m=$1 [L,QSA]

And make sure your js, css, images files are using absolute path not the relative ones. Which means their paths should either start with http:// or /.

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

2 Comments

thanks yours definitely solve the thing that i wanted. so whenever there is more parameters, i need to rewrite teh condition and new rules?
Yes that's correct, just make sure every RewriteRule is ending with L flag.
1

why not just pass everything to index.php and then handle/parse the path, e.g.

RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

Then use

$_SERVER['PATH_INFO']
$_SERVER['ORIG_PATH_INFO']
$_SERVER['QUERY_STRING']

http://php.net/manual/en/reserved.variables.server.php

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.