Rewriterule : php page to another (with parameters) cause a 500 error - apache

I have a simple question but can't find the answer.
I have a page: http://www.mysite.com/overview.php?lang=en&TM=15 and
I want to access a new page : http://www.mysite.com/aboutus/overview.php?lang=en&TM=15
.htaccess
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^overview\.php\?lang=fr&TM=([0-9]+)&TM=([0-9]+)*$ /aboutus/overview.php?lang=$1&TM=$2 [R=301, L]
Any idea to solve my problem ?
Thank you in advance
Dominique

Try this,
.htaccess
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/overview\.php$
RewriteRule ^(.*)$ /aboutus/$1 [QSA,L]
[QSA] option will Rewrite url along with query parameters, so no need to match separately for lang=en&TM=15 (if you want to pass same request parameters while rewriting url)

Related

.htaccess redirect to subdomain url with hash

I'm trying to redirect a site with the following url structure:
https://example.com/2021/about
to
https://2021.example.com/#about
https://example.com/2021/visit
to
https://2021.example.com/#visit
how can i do this?
i tried adding this to the /about directory in the original domain:
RewriteEngine on
RewriteBase /
RewriteRule (.*) https://2021.example.com/#about [R=301,NE, L]
but what i got after the redirect was
https://2021.example.com/#about2021/about
which is not right. any help is appreciated
[EDIT] i only want to apply this to some folders, like /2021/about and 2021/visit
You may use this redirect rule:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(?:www\.)?(example\.com) [NC]
RewriteRule ^(20\d{2})/(.+?)/?$ https://$1.%1/#$2 [R=301,L,NE]
Make sure this is your topmost rule in .htaccess and you clear your browser cache before testing this new rule.
Could you please try following, written based on your shown samples. Please make sure to clear your browser cache before testing your URLs. Following will only be applied to 2021/about OR 2021/visit uris.
RewriteEngine ON
RewriteCond %{HTTP_HOST} (example\.com) [NC]
RewriteRule ^(2021)/(about|visit)/?$ http://$1.%1/#$2 [R=301,NC,NE,L]

How I fix this URL rewrite issue in .htaccess?

I am trying to write SEO friendly clean URLs, using Apache Mod-Rewrite.
My existing URLs look like this:
index.php?p=my-page
index.php?p=my-page&id=3
index.php?p=my-page&cat=5
index.php?p=my-page&month=201606
I have tried it and this is my code sofar in .htaccess:
RewriteRule ^([\w-]+)/?$ index.php?p=$1 [L,QSA,NC]
RewriteRule ^([\w-]+)/([0-9]+)/?$ index.php?p=$1&id=$2 [L,QSA,NC]
RewriteRule ^([\w-]+)/([0-9]+)/?$ index.php?p=$1&cat=$3 [L,QSA,NC]
RewriteRule ^([\w-]+)/([0-9]+)/?$ index.php?p=$1&mth=$4 [L,QSA,NC]
But, My problem is, when it change 2nd variable name in query string, its always identifying as id not cat or mnt.
Can anybody tell me how fix this issue?
Thank you.

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

Match Question Mark in rewrite rule using .htaccess

I have tried it in a different way that is also not working for me.
Match Question Mark in rewrite rule
please help me on this
Redirect to different url
http://localhost/crb/index.html?q=xxxxxxxx
To
http://localhost/crb/demo/result?q=xxxxxxxx
I tried this
Options +FollowSymlinks
RewriteEngine on
rewriterule ^crb/index.html?q=xxxxxxxx(.*)$ http://localhost/crb/demo/result?q=xxxxxxxx$1 [r=301,nc]
To rewrite based on query string use :
RewriteEngine on
RewriteBase /
RewriteCond %{QUERY_STRING} ^q=xxxxxxxx(.*)$
RewriteRule ^/?crb/index.html http://localhost/crb/demo/result?q=xxxxxxxx%1 [R=301,NC]
You could try the Query String Append (QSA) flag:
RewriteRule ^crb/index.html$ crb/demo/result [NC,L,QSA]
This should append the existing query string (q=xxxxxxxx) to the new url.
https://wiki.apache.org/httpd/RewriteFlags/QSA
http://httpd.apache.org/docs/2.2/rewrite/flags.html#flag_qsa
If this code doesn't work, modify it a little and try again.

apache html request parameters

is there any way to disable/drop queries to html contents.
GET /alaswaq_property.html?d691f
GET /alaswaq_property.html?48fae
GET /alaswaq_property.html?8c106
GET /alaswaq_finance.html?fe082 if request contains filename.html?xxx then block it only allow filename.html < is this possible?
thanks in advance.
In your htaccess file or vhost config, add:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^[A-Za-z0-9]{5}$
RewriteRule \.html$ - [F,L]
If you want to simply include any query string at all, change the RewriteCond line to:
RewriteCond %{QUERY_STRING} !^$
Yes, you can use mod_rewrite to do this.
RewriteRule ^/alaswaq_property.html /alaswaq_property.html?
See http://wiki.apache.org/httpd/RewriteQueryString for stuff you can do for query string manipulation.