I have the following URL
www.example.com/index.php?tag= xxx
I want to make it like the following using .htaccess
www.example.com/xxx
I done it with this code:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.+?)/?$ /index.php?tag=$1 [L,QSA]
SO if I input this URL:
www.example.com/index.php?tag=1000
it be redirect to:
www.example.com/?tag=1000
if: www.example.com/1000 it works!
So I have dublicate URL and it's not good for seo.
How can redirect www.example.com/index.php?tag=1000 to www.example.com/1000
use this code for
.htaccess file
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.+?)/?$ /index.php?key=$1 [L,QSA]
you index.php code will be
<?php
echo $_REQUEST['key'];
?>
then call
http://sitename.com/1000
output will be :1000
How can redirect www.example.com/index.php?tag=1000 to www.example.com/1000
You can insert this rule just below RewriteBase line:
RewriteCond %{THE_REQUEST} /(?:index\.php)?\?tag=([^\s&]+) [NC]
RewriteRule ^ /%1? [R=302,L,NE]
Related
I have a URL like http://example.com/index.php/fruit/1a2b3c
I want to get the URI's for which I have written a code.
Now I want to remove the index.php from the visible URL, it should work even when the URL is http://example.com/fruit/1a2b3c and it should still point to index.php
I am on apache2 using PHP 7
Add following code to your .htaccess file.
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1 [L,QSA]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s(.*)/index\.php [NC]
RewriteRule ^ %1 [R=301,L]
change your .htaccess file to,
RewriteEngine on
RewriteCond $1 !^(index\.php)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [QSA,L]
hope this will work.
My .htaccess looks like this..
Options -Indexes
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
RewriteCond %{HTTP_HOST} ^sub\.domain\.com$ [NC]
RewriteRule ^(.*)$ https://www.domain.com/members/invite/$1 [R,L]
</IfModule>
I want to be able to redirect an URL that looks like this..
https://sub.domain.com/ZTHF76
to...
https://www.domain.com/members/invite/ZTHF76
But instead I am getting
https://www.domain.com/members/invite/index.php
I need to keep the first rule to remove index.php from the URI of the rest of the application.
Any help with this greatly appreciated.
You should reorder your rules and keep redirect rule before rewrite one:
Options -Indexes
RewriteEngine On
RewriteCond %{HTTP_HOST} ^sub\.domain\.com$ [NC]
RewriteRule ^(.*)$ https://www.domain.com/members/invite/$1 [L,R=302]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
I have the following question. Let's say I have link like
http://localhost/test/index.php/admin
I have the following htaccess:
Options -MultiViews
Options +FollowSymLinks
Options -Indexes
RewriteBase /test/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [NC,QSA,L]
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteRule (.*?)index\.php/*(.*) $1$2 [R=301,NE,L]
What it does is simply remove index.php from the URL. However, when I enter url like this:
http://localhost/test/abc/blabla/index.php
It goes on an infinite loop. What I want is to do nothing when another index.php is met in the URL. How can I achieve this? Thanks!
Replace your code with this:
Options +FollowSymLinks -MultiViews -Indexes
RewriteEngine On
RewriteBase /test/
RewriteCond %{QUERY_STRING} !(^|&)r(&|$)
RewriteCond %{THE_REQUEST} /index\.php [NC]
RewriteRule ^(.*?)index\.php(?:/(.*))?$ $1$2?r [R=302,NE,L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^((?!index\.php/).+)$ index.php/$1 [L,NC]
I have this code in my htaccess file:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9-/_]+)/?$ http://subdomain.example.com/index.php?id=$1 [L,QSA]
but everytime i go to something like http://subdomain.example.com/test/test
it should resolve to:
http://subdomain.example.com/index.php?id=test/test
which it does, but its changing my URL to be the above and its not keeping the original URL
Remove http:// from your target URL:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} =subdomain.example.com
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?id=$1 [L,QSA]
I have also corrected your regex in RewriteRule.
I am trying to rewrite:
mydomain.com/category.php?id=cat
to
mydomain.com/cat
I have used the following .htaccess code but it keeps showing a 505 error:
RewriteEngine On
RewriteRule ^([^/]*)$ /category.php?id=$1 [L]
I read on another page that it is because the page keeps looping, but I can't work out how I can fix the code.
Keep your rule like this:
RewriteEngine On
# 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 ^([^/]+)/?$ /category.php?id=$1 [L,QSA]
Try this.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^(\w+)/ category.php?id=$1 [L]
</IfModule>
You need to add RewriteCond to avoice rewrite for category.php
RewriteEngine On
RewriteCond %{REQUEUST_URI} !^ /category.php/(.*)
RewriteRule ^(\w+)/ category.php?id=$1 [L]
Ok this should work:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/category.php
RewriteRule ^(.*)$ category.php?id=$1 [R=301,L]
Demo: http://ht6.valhook.com/cat