Four specific questions regarding this htaccess file - zend-framework

#+FollowSymLinks must be enabled for any rules to work, this is a security
#requirement of the rewrite engine. Normally it's enabled in the root and you
#shouldn't have to add it, but it doesn't hurt to do so.
Options +FollowSymlinks
#Apache scans all incoming URL requests, checks for matches in our .htaccess file
#and rewrites those matching URLs to whatever we specify.
#to enable runtime rewriting engine
RewriteEngine On
#this tells mod_rewrite to leave the URL unchanged (the dash part -) and quit
#other rewwrite processing rules if the requested segment has one of those
#prefixes (that's what we asking when we use the ^ sign), on the list. If the
#prefix is in the list, all subsequent Rewrite Rules are skipped.
#So to avoid some files OR directories to be redirected we use:
RewriteRule ^(somefile|somedir|someotherfile) – [L]
1) Don't we need a condition here before these previous RewriteRule ?
#this will allow direct linkage to this extensions, regardless the case sensitive.
RewriteCond %{REQUEST_FILENAME} !\.(js|ico|zip|rar|mov|mpeg4|mp4|gif|jpg|png|css|doc|pdf|docx|wmv|mpeg|avi|mpg|flv|ppt|pptx|txt)$ - [NC]
2) Will the [NC] flag deal with all case variations here?
#if the request uri has not public...
RewriteCond %{REQUEST_URI} !^/public/.*$
#rewrite to public something...
RewriteRule ^(.*)$ /public/$1
3) Why do we have $1 and not /public/index.php on our RewriteRule?
#rewrite all requests that start with public, to public/index.php and if that's
#the case, don't run any other rule.
RewriteRule ^public/.*$ /public/index.php [NC,L]
4) since this is the last rule, can we remove the L flag ?

No, anything that starts with somefile, somedir or someotherfile will not be rewritten (-). [L] ensures that further rules (including this one) will not be processed.
Yes.
Because the RewriteCond can match /public/otherthing as well, not just /public/index.php.
No, without [L], an infinite loop will occur because the rewritten URL /public/index.php matches `^public.*$.

Related

Apache 2.4 exact redirection matching strings

I have a URL :
https://www.example.com/login/login.cgi?user=option
Want to exactly match login.cgi
If user hits https://www.example.com/login/login.cgi need to redirect to external site say www.redirect.com
If anyone hits https://www.example.com/login/login.cgi?user=option it should not cause any redirection.
I tried various option of query string and as well Rewrite rules seems to not work.
I tried using :
RewriteEngine On
RewriteCond %{QUERY_STRING} ^login.cgi$
RewriteRule ^login/$ https://www.redirect.com? [R=302,L]
This should work for you.
RewriteEngine on
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^/?login/login\.cgi$ https://example.com [R,L]
This will redirect yoursite.com/login/login.cgi to example.com .
The condition RewriteCond %{QUERY_STRING} ^$ matches empty querystring meaning that when the the URI is /login/login.cgi without any querystring the Rewriterule will be applied.
The /? in the beginning of RewriteRule pattern makes it possible to use the rule in both contexts server.config or in htaccess.

What is the order of processed rewrite rules of cq dispatcher?

I'm going to apply the following rewrite rules on my dispatcher
RewriteRule ^content/feeds/networkapp/ios/1.0/config(.*)?$ /content/feeds/ios/feed.config.json [L,NC]
RewriteRule ^content/feeds/networkapp/ios/((\d\.)+\d/)?config(.*)?$ /content/feeds/ios/$1feed.config.json [L,NC]
Does first rewtite rule will be executed?
I need to revrite :
...../ios/1.0/config to /ios/feed.config.json
...../ios/x.x.x/config to /ios/x.x.x/feed.config.json
As you may see,I have used [L] flag. This means that if the rule matches, no further rules will be processed.
RewriteRule ^content/feeds/networkapp/ios/1.0/config(.*)?$ /content/feeds/betnow/ios/feed.config.json [L,NC]
RewriteRule ^content/feeds/networkapp/ios/((\d\.)+\d/)?config(.*)?$ /content/feeds/ios/$1feed.config.json [L,NC]
[L] flag on apache documentation

How to make a redirect in .htaccess for pages from different subdomains

I'm not very advanced at programming and I need to make a 301 redirection from one specific subdomain page to another. The tricky part, at least for me, is that the pages are on two different subdomains. So far I've only managed to 301 ALL pages to the target or crashing the whole site.
I've used many, but are currently at:
RewriteCond %{HTTP_HOST} !^spiele.deutschedownloads.de/?DriverScanner/Diverse//download/4770$ [NC]
RewriteRule ^(.*)$ http://programme.deutschedownloads.de/?DriverScanner/Drivers/Werkzeuge-Diverse/download/4413 [L,R=301]
What I want to do is simply to 301 redirect
spiele.deutschedownloads.de/?DriverScanner/Diverse//download/4770
To
http://programme.deutschedownloads.de/?DriverScanner/Drivers/Werkzeuge-Diverse/download/4413
Any help is most appreciated!
This should work:
RewriteCond %{HTTP_HOST} ^spiele\.deutschedownloads\.de$ [NC]
RewriteCond %{QUERY_STRING} ^DriverScanner/Diverse//?download/4770/?$ [NC]
RewriteRule ^ http://programme.deutschedownloads.de/?DriverScanner/Drivers/Werkzeuge-Diverse/download/4413 [R=301,L]
First condition matches the domain in case they are both on the same root folder.
Second condition matches the query string.
If both conditions are OK it redirects.

Redirecting error using .htaccess

rewriting the url RewriteRule ^about/ /about.php [L,R=301] but the page is accessed via /about.php directly also. Please help to how to redirect .php file
Replace your code with this code:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+about\.php\s [NC]
RewriteRule ^ /about/ [R=302,L]
RewriteRule ^about/?$ /about.php [L,NC]
You can use this free .htaccess Redirect Generator:
http://htaccessredirect.net/
with this tool you can easily create your redirection code for .htaccess.
You can use rule to hidden redirect:
#use [L] to hidden [R] to shown redirect
RewriteRule ^(about|faq|home)/?$ $1.php [L]
#to prevent access from about.php simply do this:
RewriteRule (.+)\.php$ $1/ [R=301]
#you need to know 301 redirect will be cached with browser for long time
#so if you change rule - will be no effect for some visitors

Disable mod_rewrite on index

This is my mod_rewrite code:
Options +FollowSymlinks
RewriteEngine on
# ————————————————————————-
# > URL REWRITING
# ————————————————————————-
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^(.*)/diario$ hotsite/diary.php
RewriteRule ^(.*)/recados$ hotsite/messages.php
RewriteRule ^(.*)/fotos$ hotsite/photos.php
RewriteRule ^(.*)/videos$ hotsite/videos.php
RewriteRule ^(.*)/contato$ hotsite/contact.php
RewriteRule ^([a-z0-9._\-]+)$ hotsite/index.php [L]
It works just like facebook profiles. Whenever I type "mywebsite.com/user.name" it goes to that user page. I can also type "mywebsite.com/user.name/videos" to go to a specific page in the user profile.
However, I can't access "mywebsite.com" anymore, because it redirects to "mywebsite.com/hotsite/index.php". How can I disable this behavior and leave the redirects only when someone types a user name at the end?
Thank you very much.
The RewriteCondition(s) only affect the RewriteRule that comes immediately after that. So, to stop redirecting htp://mywebsite.com/aDirThatExists like http://mywebsite.com/aboutUs you need to repeat the rewrite conditions as
RewriteCond %{SCRIPT_FILENAME} !-d # if not a directory
RewriteCond %{SCRIPT_FILENAME} !-f # and not a file
RewriteRule ^([a-z0-9._\-]+)$ hotsite/index.php [L]
This, however, should not affect a root URL request i.e. http://mywebsite.com/ because your regex clearly matches one or more characters after / because of the []+ plus sign.