.htaccess hide question mark from address - apache

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]

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>

Enable human readable URL's in .htaccess

Preface: Yes this question seems like duplicated, and I found related questions, but answers from there didnt help to me. :(
Hello, I want to add human readable URL's support for my PHP project. For now my URL quesry string looks like:
index.php?url=main/index
I would like to make it looks like:
index.php/main/index
I read following articles:
Stackoverflow
Cheatsheet
Stackoverflow
Stackoverflow
But when I do this:
var_dump($_GET['url']); // get empty array
, get empty array like no url parameter added.
My current .htaccess:
DirectoryIndex index.php
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^(.*)$ index.php?url=$1 [NC]
Can somebody help me please? Thanks!
URL: http://domain.com/index.php/controller/action
Rewritten URL: http://domain.com/index.php?url=controller/action
.htaccess
DirectoryIndex index.php
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^index.php/(.*)$ /index.php?url=$1 [L,QSA]
Explanation:
The .* in the pattern ^index.php/(.*)$ matches everything after index.php/ on the incoming URL. The parentheses helps to capture the part as variable $1, which is then added at the end of the substitution URL /index.php?url= + $1.
[L, QSA]:
L ignore other rewrite rules, if this fits.
QSA means query string append.
You have
index.php?url=main/index
Yuo want to rewrite (and then user redirect) to this
index.php/main/index
What about trying this?
DirectoryIndex index.php
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} ^url=([a-z]+)/([a-z]+)$
RewriteRule ^.*$ http://mydomain.site/index.php/%1/%2 [R=302,L]
R=301 or 302 depend on your need
On this example i assumed that on the original url there are only a-z chars.
Just to clarify (due the fact generally the process is inverse) on this way the users will be redirect, this rules does not convert links on your page.
In line
RewriteRule ^(.*)$ index.php?url=$1 [NC] the (.*) matches the part of the url up to '?' where the query begins.
To use the values passed in the query you need the QSA flag. Means Query String Append.
If Your URL : www.abcd.com/index.php/abcd/...
.htaccess
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
Try the below code, Only considered for index.php you can replace it as per your requirement. Let me know if you need further assistance.
DirectoryIndex index.php
Options +FollowSymLinks
RewriteEngine ON
RewriteBase /
RewriteRule ^(index\.php)/([0-9a-zA-Z\/_-]{1,99}) index.php?url=$2
What worked for me is:-
<?php var_dump($_GET); ?> this is the only thing I did on url http://localhost/baba.php/abcd . and original .htaccess file
DirectoryIndex baba.php
RewriteEngine ON
RewriteBase /
RewriteRule ^(baba\.php)*/([0-9a-zA-Z\/_-]{1,99}) baba.php?url=$2
For Magento 2.4 Magento will always drop any GET parameters from the URL in a htaccess rewrite. The only way I found to make it work was to create a rewrite module. The setup is here: https://magento.stackexchange.com/a/158811/109113

Where is my mod rewrite fail?

I have got url
ipaddr/opensys/base/
and some other similar, like
ipaddr/opensys/base/something.php?olol=yep
I want to remove from url "opensys" and display there "center", i want to see this links working:
ipaddr/center/base/
and
ipaddr/center/base/something.php?olol=yep
I did it with symlinks, but it was not good, because system is very difficult and with symlink some plugins not works, I want to do it with .htaccess only, after it all will be ok.
My htaccess is:
but links, which i want to see is not working, why?
RewriteEngine on
RewriteRule ^/opensys/base/(.*)$ /center/base/$1 [L]
RedirectMatch 301 ^/opensys/base/(.*)$ /center/base/$1
Redirect works good, but i see 404, rewrite rules is not working. Why?
You also need to handle the /center/base/ now in the .htaccess file as you must be handling opensys earlier. Something like this -
RewriteRule ^/opensys/base/(.*)$ /center/base/$1 [R=301]
RewriteRule ^/center/base/(.*)$ /index.php?args=$1 [QSA,L]
You can use this code in root .htaccess:
RewriteEngine on
RewriteCond %{THE_REQUEST} /opensys/(base/\S*)\s [NC]
RewriteRule ^ /center/%1 [R=301,L,NE]
RewriteRule ^center/(base/.*)$ opensys/$1 [L,NC]

.htaccess being overpowered by file structure in apache2

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.

direct all webpage requests with .index.html to /

I want to direct all requests for any URL that ends with index.html to /. I have one domain on the server.
Example:
If someone wants "www.thissite.com/index.html--it is directed to www.thissite.com/.
AND
if someone wants "www.thissite.com/anyword/index.html"--it is directed to www.thissite.com/.
AND
if someone wants "www.thissite.com/folderdoesntexistonthissite/index.html"--it is directed to www.thissite.com/.
What is the .htaccess code that would enable this? (Both the rewritecondition and rewriterule)
This doesn't quite do the job:
RewriteCond %{THE_REQUEST} index\.html [NC]
RewriteRule index\.html$ http://www.thissite.com/$1 [R=301.L]
You could try this (without RewriteCond):
RewriteRule /index\.html$ http://www.thissite.com/ [R=301,NC,L]
Maybe the Error was the Period in [R=301.L].
You will need to use %{REQUEST_URI} variable to match in RewriteCond otherwise Apache strips out starting / in RewriteRule. Use below code in your .htaccess file:
Options +FollowSymlinks -MultiViews
RewriteEngine on
RewriteCond %{REQUEST_URI} ^.*/index.html$ [NC]
RewriteRule . / [R=301,L]