Following rule doesn't work for subfolder rewriting.
RewriteRule ^cat/([0-9a-zA-Z]+) cat.php?id=$1
RewriteRule ^cat/([0-9a-zA-Z]+)/([0-9a-zA-Z]+) cat.php?id=$1&sid=$2
For example With this rule
<?php
$id='News';
$sid='Politics';
?>
..
In next page, while echoing $_GET['sid'], it doesn't work
Notice: Undefined index: sid in ...
But this rule
RewriteRule ^cat/([0-9a-zA-Z]+)/([0-9a-zA-Z]+) cat.php?id=$1&sid=$2
works, if only there is two querystring parameters
..
but it generate ERROR 500 if there is only one parameter
<a href="cat/<?php echo $id?>>..</a>
Try with below,
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^cat/([0-9a-zA-Z]+)$ cat.php?id=$1 [L]
RewriteRule ^cat/([0-9a-zA-Z]+)/([0-9a-zA-Z]+)$ cat.php?id=$1&sid=$2 [L]
Related
This is my simple htaccess code:
RewriteRule ^books/([A-Za-z0-9.]+)$ library/search.php?zig=$1 [NC,L]
My code is working fine for the followings:
mydomain/books/math
mydomain/books/english
mydomain/books/physics.applied
as
library/search.php?zig=math
library/search.php?zig=english
library/search.php?zig=physics.applied
But my code is not working only for
mydomain/books/
it is acting as
library/search.php?zig=index.php
There is no subject named index.php. I want to remove this index.php. My search function should not work for mydomain/books/
You can add a RewriteCond to ignore all files and directories from rewrite:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^books/([A-Za-z0-9.]+)$ library/search.php?zig=$1 [NC,L,QSA]
I'm trying to use the Url rewrite using "RewriteRule".
I would use this link to show a new article in my blog:
https://www.example.com/article/how-to-visit-italy-in-winter
The original script (including vars) is
https://www.example.com/post.php?idpost=how-to-visit-italy-in-winter
This is my .htaccess
RewriteEngine on
RewriteRule ^article/$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .$ https://www.example.com/post.php?idpost=$1 [L]
but it doesn't work, the browser redirect to:
https://www.example.com/post.php?idpost=
I'm trying to resolve about 2 days witout success :(
Thank you.
You rule looks fine except for two things . Your $1 back reference is undefined and empty as you are not capturing any URI. To capture parts of the uri you need to use Regex capture-groups (.*) .
2) You need to use an absolute path instead of the full url as your RewriteRule`s destination if you want to silently redirect the url.
RewriteEngine on
RewriteRule ^article/$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule article/(.+) /post.php?idpost=$1 [L]
I have the following rule:
RewriteRule ^(.*)$ index.php?ip=$1 [L]
But it's not working, instead it is loading:
https://example.com/?ip=index.php
Am I missing something?
Your rule is looping because there is no condition to stop rewriting for existing files and directories.
After first rewrite it becomes:
index.php?id=1.2.3.4
and after second rewrite URI becomes:
index.php?id=index.php
You can use this rule to fix this behavior:
# If the request is not for a valid directory
RewriteCond %{REQUEST_FILENAME} !-d
# If the request is not for a valid file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?ip=$1 [L,QSA]
I am trying to redirect a bunch of old blog article URLs using the .htaccess file:
RedirectMatch ^/index\.php/global/article/(.*)$ http://www.mywebsite.com/blog/article/$1
This doesn't really work, however, because my CMS seems to get confused by the index.php bit and keeps adding ?symphony-page= to all the URLs.
It's probably this part that is responsible:
### FRONTEND REWRITE - Will ignore files and folders
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*\/?)$ index.php?symphony-page=$1&%{QUERY_STRING} [L]
Can anybody help?
Please try the following (comments included to explain):
RewriteEngine On
# First, redirect the old URIs to the new ones via a 301 redirect.
# This will allow the CMS to take over using the rules that follow.
RewriteRule ^index.php/global/article/(.+)$ /blog/article/$1 [L,R=301]
# Frontend Rewrites - for the CMS
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*\/?)$ index.php?symphony-page=$1&%{QUERY_STRING} [L]
Try this:
#-- Input URL >> http://www.mywebsite.com/index.php/global/article/abc
### FRONTEND REWRITE - Will ignore files and folders
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*\/?)$ index.php?symphony-page=$1&%{QUERY_STRING}
RewriteCond %{REQUEST_URI} ^/index\.php/global/article/(.*)$
RewriteRule ^.*$ blog/article/%1 [R=301, L]
#--Output URL >> http://www.mywebsite.com/blog/article/abc
I've tested the above with this htaccess.madewithlove and it seems like it will work just fine, hopefully it will work for you too
Screenshot:
i have a htaccess file which redirectes all the requests to index.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* ./index.php
My question is i would like to make a redirect to folder which doesn't exist and it should not affect the present htaccess redirects to index.php. since it is linked to entire website
for eg
domain.com/search=kannan&id=21
to
domain.com/kannan
I just need a way to allow only this request and everything else goes to index.php, any ideas...
You could use a condition to capture requests that match a specific pattern, like:
RewriteCond %{REQUEST_URI} ^domain.com/search(.+)$
Then do your rewrite. Or: http://www.google.com/search?q=htaccess+query+string+rewrite
i suggest you to pass id through form . Means use Form post method to pass id then you only need to have 'domain.com/kannan' in url and id will passed as post
Use similar type of code as below -
<form method="post" action="domain.com/kannan">
<input type="hidden" value="21" name="id" />
</form>
In this way form will be posted to domain.com/kannan with id = 21 and url will be domain.com/kannan
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/public/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /public/$1
#RewriteRule ^ index.php [L]
</IfModule>