Reputation: 179
Hello I have this rewrite-rule example it makes the following example:
[http://localhost/project/index.php?url=something]
on my site I use it to make
[http://localhost/project/index.php?url=task/add]
shown as
[http://localhost/project/task/add]
This is my code
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]
I need to make 3 other things
make url [http://localhost/project/index.php?url=tasks/view/&page=2]
shown as [http://localhost/project/tasks/view:2]
or [http://localhost/project/tasks/view#2]
then my upload folder named (files) I wanna to redirect anyone get any
file from this folder just browser
download files on upload folder named (files) with custom url like as [http://localhost/project/getfile/1]
Upvotes: 0
Views: 77
Reputation: 20737
First of all I want to remind you that #
is the 'anchor' part of an url. It is never sent to the server, so rewriting to it is probably not the best idea.
What your existing rule does, is internally rewriting all requests that do not map to an existing file, directory or symlink to index.php. If you want to rewrite urls like http://localhost/project/tasks/view:2
to be rewritten to http://localhost/project/index.php?url=tasks/view&page=2
, you'll need to add this rule before the rule you already have. Otherwise the more general rule would match it before the more specific rule can.
I also presume you have your .htaccess
in your /project/
directory.
make url
[http://localhost/project/index.php?url=tasks/view/&page=2]
shown as
[http://localhost/project/tasks/view:2]
or
[http://localhost/project/tasks/view#2]
Adding the following rule before your existing rule should handle those urls nicely.
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^tasks/view:(.+)$ index.php?url=tasks/view&page=$1 [QSA,L]
Alternativelly, why don't you simply explode( $_GET['url'], ':' );
in index.php
instead of this rule.
then my upload folder named (files) I wanna to redirect anyone get any
file from this folder just browser
If you want to stop all direct requests to /project/files
, you can use the %{THE_REQUEST}
trick and the [F]
(forbidden) flag. If you want to display a custom error page, add an errordocument handler for the forbidden status code.
RewriteCond %{THE_REQUEST} ^(GET|POST)\ /project/files
RewriteRule ^ - [F,L]
download files on upload folder named (files) with custom url like as [http://localhost/project/getfile/1]
Remember that for every request you send to the server, Apache will match it against a regex in the RewriteRule and either rewrite it internally or redirect the user. To internally rewrite a request to /project/getfile/1
to /project/files/1
you can use the following rule. Add it before the rule you already have.
RewriteRule ^getfile/(.*)$ /files/$1 [L]
I encourage you to read the documentation for mod_rewrite.
Upvotes: 1