.htaccess being overpowered by file structure in apache2 - apache

I have a .htaccess file and am using mod rewrite to redirect /tags to /tags/. When the directory contains a file called tags.php, it doesn't work, but when I remove that file it does. What setting do I need to change to make the .htaccess file overpower the file structure? I'm running Apache2 on Ubuntu 11.10 with PHP.
RewriteEngine On
RewriteBase /
RewriteRule ^tags/([a-zA-Z0-9-_.\ ]+)$ tags/$1/ [R]
RewriteRule ^tags/([a-zA-Z0-9-_.\ ]+)/([0-9]*)?$ tag.php?tag=$1&page=$2
RewriteRule ^tags$ tags/ [R]
RewriteRule ^tags/$ tags.php

Try adding an L to your tags rule to stop further processing i.e.
RewriteRule ^tags$ tags/ [R,L]

Your rules are in the wrong order, and you've forgotten the [L] to stop processing the rewrite rules. Try:
RewriteEngine On
RewriteBase /
RewriteRule ^tags$ tags/ [R, L]
RewriteRule ^tags/$ tags.php [QSA]
RewriteRule ^tags/([a-zA-Z0-9-_.\ ]+)$ tags/$1/ [R,L]
RewriteRule ^tags/([a-zA-Z0-9-_.\ ]+)/([0-9]*)?$ tag.php?tag=$1&page=$2 [L]

Disable Multiviews in the server configuration.

Related

Multiple url redirection in apache :mod_rewrite

I am new to Apache and wish to redirect an existing url (1) to new url(2) and then to final url(3). The redirection from url (1) to url(2) is existing redirect rule defined and we cannot by pass it. Due to this we cannot jump form jump directly from url (1) to url(3). Below is the exsitng code:
for eg:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^/portal-web-payment/(.*)$ /portal-web/$1 [R]
RewriteRule ^/portal-web/abc/portal/payment/web/mbbQuickRecharge/(.*)$ - [L]
</IfModule>
I wish to insert below rule into this existing one, which is not working.
RewriteRule ^/(.*)(portal-web/abc/portal/payment/web/mbbQuickRecharge/PrepaidQuickRechargeController.jpf)(.*)$ http://yahoo.com/servlet/du/en/mobilebroadbandrecharge.html [L,R=302]
Below is the final Redirect url we wrote, which is not working.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^/portal-web-payment/(.*)$ /portal-web/$1 [R]
RewriteRule ^/portal-web/abc/portal/payment/web/mbbQuickRecharge/(.*)$ - [L]
RewriteRule ^/(.*)(portal-web/abc/portal/payment/web/mbbQuickRecharge/PrepaidQuickRechargeController.jpf)(.*)$ http://yahoo.com/servlet/du/en/mobilebroadbandrecharge.html [L,R=302]
</IfModule>
If suppose the rule is not working is due to already existence of apache flag [L], we cannot place our url before this due to project constraints.
Kindly suggest a way.
Thanks in advance.
Update 1:
Hi, its in .conf file.
the servername is our local env : in.test.it:90
<IfModule mod_rewrite.c>
ServerName in.test.it:90
RewriteEngine On
RewriteRule ^/portal-web-payment/(.*)$ /portal-web/$1 [R]
RewriteRule ^/portal-web/abc/portal/payment/web/mbbQuickRecharge/(.*)$ - [L]
RewriteRule ^/(.*)(portal-web/abc/portal/payment/web/mbbQuickRecharge/PrepaidQuickRechargeController.jpf)(.*)$ http://yahoo.com/servlet/du/en/mobilebroadbandrecharge.html [L,R=302]
</IfModule>

Htaccess not getting 'GET' variables even with QSA flags

I can't seem to get my 'GET' variables passing through with my htaccess code. Here it is below:
<IfModule mod_rewrite.c>
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php[\s?] [NC]
RewriteRule ^ %1 [R=301,L]
RewriteRule ^/(.*)/(.*)/(.*)$ v.php?shareid=$1&filename=$2 [QSA, L]
</IfModule>
I have v.php in the root, not in any folder and I am trying to achieve the following URL:
http://localhost/v/ubgvfmrsazwxoyp/Screen%20Shot%202015-11-05%20at%2020.51.45.png
where ubgvfmrsazwxoyp is the shareid and Screen%20Shot%202015-11-05%20at%2020.51.45.png the file name.
None are getting registered when page is loaded.
Note: I also want to keep .php extensions hidden.
Any ideas?
RewriteEngine On
RewriteBase /
RewriteRule ^v/([^/]+)/(.*)/?$ v.php?shareid=$1&filename=$2 [L]
You were previously getting v as the shareid and ubgvfmrsazwxoyp as the filename.
NOTE: The above code is specifically for an .htaccess file inside the server root directory. If the rewrite rules are going in the vhost config or the server config file, you'll need to use:
RewriteRule ^/v/([^/]+)/(.*)/?$ v.php?shareid=$1&filename=$2 [L]

Unable to Rewrite directory with fullstop in name to another

I need to rewrite a directory and all is contents to a new directory however I am having issues I think due to the source directory having a full stop in it.
i.e.
http://example.com/1.0/ to http://example.com/newfolder/
Here is the rule I am trying
RewriteEngine On
RewriteBase /
RewriteRule ^1\.0$ http://example.com/newfolder/ [NC,R=301,L]
You can use:
RewriteEngine On
RewriteRule ^1\.0(/.*)?$ http://example.com/newfolder$1 [R=301,L]
This will redirect /1.0/anything to /newfolder/anything

.htaccess hide question mark from address

What am I doing wrong?
I have a link :
Link Name
I am need to make an address from:
eshop.mydomain.com/norma/something1/something2/something3/
this adress:
eshop.mydomain.com/norma-something1-something2-something3.html
the only thing I can do is
eshop.mydomain.com/?norma-something1-something2-something3.html
I need to hide the question mark, but I do not have any idea how :(
Here is my .htaccess
#php_value memory_limit 256M
RewriteEngine On
RewriteBase /
RewriteRule /index.php / [R=301]
RewriteRule ^norma/([^/]+)/([^/]+)/([\d\.]+)$ %{DOCUMENT_ROOT}/index.php?$1-$2&-$3.html [L,QSA]
ErrorDocument 404 /doc/e404/
You're adding that question mark in your rewrite rule:
# right here -----------------------------------------------------------v
RewriteRule ^norma/([^/]+)/([^/]+)/([\d\.]+)$ %{DOCUMENT_ROOT}/index.php?$1-$2&-$3.html [L,QSA]
But I suspect it may be a couple of things that's causing this redirect to happen when it really should be a rewrite internally on the server side. Try changing your rules to this:
RewriteEngine On
RewriteBase /
# this L is important ------------v
RewriteRule ^/?index.php / [R=301,L]
RewriteRule ^norma/([^/]+)/([^/]+)/([\d\.]+)$ /index.php?$1-$2&-$3.html [L,QSA]

Apache .htaccess file redirect

Should be easy for someone.
My files are in this directory: /user/home/peter/mygame/production/
I am required to access my site using: www.foo.com/peter (which brings me to /user/home/peter/)
How do I tell apache:
www.foo.com/peter reads from /user/home/peter/mygame/production/
Thanks.
RewriteEngine On
RewriteBase /peter
# To avoid the infinite loop.
RewriteCond %{REQUEST_URI} !^/peter/mygame/production/
RewriteRule ^(.*)$ mygame/production/$1 [L]
(Assuming this is going into "/user/home/peter/.htaccess".)