Htaccess not getting 'GET' variables even with QSA flags - apache

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]

Related

.htaccess Remove filename from url

I'm trying to remove: "site.php" from my url:s, which look like
"example.com/custom-foldername/site.php", so the url:s would look like "example.com/custom-foldername"
Currently it's not working at all. Basically my site just doesn't change the url. I know that the .htaccess file is being read, because if i write junk code in it, it gives error 500.
Here is my current .htaccess code
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
Options -Indexes
RewriteRule ^site\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /site.php [L]
</IfModule>
The code you posted is a front-controller pattern - it rewrites every request for non-existent files to /site.php in the document root (not /custom-foldername/site.php).
And nor will a RewriteRule pattern like ^site\.php$ match a request like /custom-foldername if the .htaccess file is in the document root.
I'm trying to remove site.php from my URLs...
From all your URLs? Is site.php present in all your URLs? So, site.php is your front-controller?
If site.php really is your front-controller then try something like the following instead:
Options -Indexes
RewriteEngine On
RewriteBase /custom-foldername
RewriteRule site\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ site.php [L]
This rewrites everything that doesn't map to a physical file or directory to /custom-foldername/site.php.
UPDATE: I solved this my myself while ago, but forgot to update
So, i found the solution and here's my current .htaccess file, if someone is ever having the same problem
RewriteEngine On
RewriteBase /
Options -Indexes
DirectoryIndex site.php site.html
When user "asks" for folder directory (example.com/cats) apache looks for "site.php or site.html" files inside it. (example.com/cats/site.php) If it finds either on of them it displays it to the user as (example.com/cats). If either file isn't found it gives normal "404 not found error"

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 redirect url with parameters in a new url

I need to redirect my old link(deleted) in my new link with a .htaccess file,
for example,
From: http://www.example.com/page.php?value=2 (deleted)
To: http://www.example.com/detail.php?d=150
I tried with this but don't work. Becouse the file (page.php) does not exist, then the server give me 404 page not found.
My .htaccess
<Files ~ "^\.(htaccess|htpasswd)$">
deny from all
</Files>
RewriteEngine On
RewriteRule http://www.example.com/page.php?value=2 http://www.example.it/detail.php?d=150 [END,R=301]
order deny,allow
Can you help me?
RewriteRule directive does not receive the entire url, but the part of URI relative to the directive your htaccess file is inside. Also, it doesn't receive the query parameters, you'll have to access them with the RewriteCond directive. So, it should be:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^value=2$
RewriteRule ^page.php$ /detail.php?d=150 [R=301,L,QSD]
Try :
RewriteEngine on
RewriteCond %{THE_REQUEST} /page\.php\?value=2$
RewriteRule ^ http://example.it?page.php?d=150 [L,R]
This would redirect
http://example.com/page.php?value=2
to
http://example.it/detail.php?d=150
Reference :
https://httpd.apache.org/docs/current/mod/mod_rewrite.html

Friendly url in apache2

Now, have the next .htaccess (in the root folder):
Options -Indexes
Options -Multiviews
RewriteEngine on
# Ocultar extension php (hidden .php)
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
# Url amigable (frienly url)
RewriteBase /
Rewriterule ^owner/servicios/(.+)/$ owner/servicios.php?servicio=$1
I expect when the user access try to "domain.com.ar/owner/index/" show the page "index.php". This not work, but, i access "domain.com.ar/owner/index" works.
On the other hand, when the user try to access "domain.com.ar/owner/servicios/servicio_uno/", $_GET value of "servicio" should be "servicio_uno", but is: "servicio_uno/.php/servicio_uno ".
And "domain.com.ar/owner/servicios/servicio_uno" shows 500 internal error.
Any ideas ?.
depending on where is your htaccess located (root directory or /owner directory)
//if in root
RewriteBase /
Rewriterule ^owner/servicios/(.+)/$ owner/servicios.php?servicio=$1
//if in owner directory
RewriteBase owner/
Rewriterule ^servicios/(.+)/$ servicios.php?servicio=$1
Hope it helps.
Try the following
RewriteEngine On
RewriteBase /owner/servicios/
RewriteRule (.*) /owner/servicios.php?servicio=$1
RewriteRule ^owner/servicios/servicios.php/(.*) servicios.php?servicios=servicios=$1 [QSA,L]
Hope this helps.

replace a string in url in .htaccess

I would like to redirect www.hostname.com/some path/?cpao=12 to www.hostname.com/some path/?kmas=12.
Essentially replacing the word cpao with kmas and keeping everything else the same.
Any help will be appreciated.
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} ^cpao=([^&]*) [NC]
RewriteRule ^ %{REQUEST_URI}?kmas=%1 [R,L]
RewriteRule ^hostname.com/somepath/\?cpao([0-9]+)$ hostname.com/somepath/\?kmas=$1
you use regex in htaccess $1 is the numbers that was catched in group 1