I do not understand anything .htaccess and I need a redirection to cache.
Currently use the following rule:
RewriteRule ^movie/(.*)/(.*)/(.*)$ app.php?view=movie&theatre=$1&ordem=$2&movie=$3 [L,QSA]
That is, the requested URL
movie/jardins/0/robocop
redirects to
app.php?view=movie&theatre={jardins}&ordem={0}&movie={robocop}
But I want to redirect api/cache/html/{jardins}/{0}/{robocop}.html if file exists.
Recalling that {jardins} and {0} are directories.
How to do this? :(
You can have:
RewriteEngine On
RewriteBase /
RewriteCond %{DOCUMENT_ROOT}/app/cache/html/$1/$2/$3\.html -f [NC]
RewriteRule ^movie/(.*)/(.*)/(.*)$ app/cache/html/$1/$2/$3.html [L,NC]
RewriteRule ^movie/(.*)/(.*)/(.*)$ app.php?view=movie&theatre=$1&ordem=$2&movie=$3 [L,QSA]
Related
I've setup some rewrite rules to cleanup the URLs of my page. These rewrites work fine, except for some downloads where i don't want to rewrite the URL.
I've tried several Rules to exclude the "files" folder:
1#:
RewriteCond %{REQUEST_URI} !/files[0-9]*/
#Rewrite ulrs:
RewriteRule ^(.*)$ index.php?%{QUERY_STRING} [L]
2#:
RewriteCond %{REQUEST_URI} !^./files
#Rewrite ulrs:
RewriteRule ^(.*)$ index.php?%{QUERY_STRING} [L]
3#:
RewriteRule ^files - [L]
4#:
Putting a new .htaccess file in the "files" folder with
RewriteEngine Off
Are there any other methods I could try?
I do want to redirect to the pdf download i've setup without rewriting. just like:
<a href="files/myDownload.pdf">
If I quote the rewrite rule:
#RewriteRule ^(.*)$ index.php?%{QUERY_STRING} [L]
It no longer rewrites the url and i can access my download, so i just need to get the folder excepted from the rule.
Do you have any Ideas or tips?
All the tries except for #2 should have worked. Please note that the order in which you put your RewriteRules is also very important.
Can you give the following a try:
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/files/ [NC]
RewriteRule ^ index.php?%{QUERY_STRING} [L]
I realise there are similar questions but I'm trying to work out how I can rewrite the following URL:
http://www.myWEBaddress.com/?month=200904
to
http://www.myWEBaddress.com/my-page.php?month=200904
Regards
Add the following to the .htaccess file in the root directory of your site.
RewriteEngine on
RewriteBase /
RewriteCond %{QUERY_STRING} (^|&)month= [NC]
RewriteRule ^ my-page.php [L]
If you want to change the URL that the user sees in their browser address bar, change the last rule to
RewriteRule ^ my-page.php [L,R=301]
i have a mod_rewrite redirection problem i cannot figure out.
all requests from a specific domain get "silently" rewritten into a designated subdirectory. e.g. www.mydomain.net/hello.html retrieves the file in /net/hello.html. the following .htaccess (placed in my hosting root) achieves this perfectly:
RewriteEngine on
RewriteBase /
RewriteCond %{ENV:REDIRECT_STATUS} 200 # <-- i will need this later. read to the end of the post.
RewriteRule .* - [L]
rewriteCond %{HTTP_HOST} ^www.mydomain.net$
rewriteCond %{REQUEST_URI} !^/net.*$
rewriteRule (.*) /net/$1 [L]
however, direct URLs into this directory however should visibly redirect with a 301 to the URL without that subdirectory. e.g. www.mydomain.net/net/hello.html should redirect to www.mydomain.net/hello.html (which than still retrieves the file in /net/hello.html). my .htacces file for this (placed in /net) unfortunately doesn't work:
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^localhost$
RewriteRule ^(.*) /$1 [R=301,L]
i get an infinitive redirect loop despite the RewriteCond %{ENV:REDIRECT_STATUS} 200 block in the root .htaccess file... so what's wrong?
btw, i have to use mod_rewrite, because the site is externaly hosted and i have no access to the apache configs.
many thanks for any pointers.
Inspect the HTTP request line in THE_REQUEST instead:
RewriteCond %{THE_REQUEST} ^GET\ /net[/? ]
RewriteRule ^net($|/(.*)) /$2 [L,R=301]
OK, so we were working in the wrong directory, meh!
We have a .htaccess file that is setup to redirect some files to a PHP script. Now we are adding some hard files which we want to bypass this redirect. So far this does not seem to be working and we are stumped.
Below is our initial .htaccess file contents after starting the engine which is working for another app already:
RewriteCond $1 !^(index\.php|robots\.txt|favicon\.ico)
RewriteRule ^(.*)$ /index.php/$1 [L]
We are trying to load files now from /directory/ So we have tried adding each of these to the RewriteCond section:
RewriteCond %{REQUEST_URI} !directory
RewriteCond $1 !^(index\.php|i/|robots\.txt|favicon\.ico|directory)
Neither seems to be working. Any ideas on how to get this to load?
Examples:
Should redirect
http://example.com/thisredirects/
Should not redirect
http://example.com/directory
http://example.com/directory/
http://example.com/directory/index.php
etc.
have you tried making a second .htaccess file in the /directory dir and doing a NoRewrite in it?
Try this:
Wont redirect
RewriteRule directory/.* - [L]
Redirects
RewriteRule ^$ thisredirects/ [L]
RewriteRule (.*) thisredirects/$1 [L]
It seems you want to redirect anything that isn't actually an existing file in your docroot to your index.php. This little bit of rewrite should handle that:
RewriteCond %{REQUEST_FILENAME} -s [OR] # file with size
RewriteCond %{REQUEST_FILENAME} -l [OR] # file is a link
RewriteCond %{REQUEST_FILENAME} -d # file is a directory
RewriteRule ^.*$ - [NC,L] # don't rewrite [last rule]
RewriteRule ^(.*)$ /index.php/$1 [NC,L] # everything else gets sent to index.php
The [OR] operator may be what you are looking for on the RewriteCond as well.
Also if you just want to whitelist the /directory portion you could put a Rule before your redirects that is marked [L] for "last rule"
RewriteRule ^/directory.*$ - [NC,L]
Im trying to create a rewrite rule to a different directory, but unfortunatly its not working.
My current rewrite sends everything back to the index.php file unless the first word in the query string is admin. The rewrite rule for 'admin' is to admin.php, but i actually want it to go to /var/www/html/website.com/admin/admin.php (instead of the file in the same directory).
This is current .htaccess file.
RewriteEngine On
RewriteRule ^(.*\/?).*(css|images|js/)+.*$ - [L]
RewriteRule ^\/?admin\/?(.*)$ admin.php?url=$1 [QSA,L]
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
If i change the rewrite rule for admin to use a different directory..
RewriteRule ^\/?admin\/?(.*)$ /var/www/html/website.com/admin/admin.php?url=$1 [QSA,L]
It breaks the site. Any ideas?
Thanks.
It's actually quite simple, you're using the system path, while web path is needed.
Try the following line:
RewriteRule ^\/?admin\/?(.*)$ /subfolder/admin.php?url=$1 [QSA,L]
Try these rules:
RewriteRule ^admin($|/(.*)) admin/admin.php?url=$2 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* index.php?url=$0 [QSA,L]