How can I rewrite a single URL with the code below?
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L,NC]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [L]
You can change your regex pattern to make it target only home.php:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} \s/+(home)\.php[?/\s] [NC]
RewriteRule ^ %1 [R=301,L]
RewriteRule ^(home)/?$ $1.php [L]
Related
My Original URL
http://www.mcoh.co.in/blog-single?category=Blog&id=Janurary%202018%20Product%20training%20Scores
and Expecting in:
http://www.mcoh.co.in/mcohBlog/Janurary%202018%20Product%20training%20Scores
But Am receiving same url as original.
## hide .php extension
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L,NC]
## To internally redirect /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [L]
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteRule ^mcoh([^/]*)/([^/]*)\$ /blog-single?category=$1&id=$2 [L]
Your problem with this line :
RewriteRule ^mcoh([^/]*)/([^/]*)\.php$ /blog-single?category=$1&id=$2 [L]
replace it with :
RewriteRule ^mcoh([^/]*)/([^/]*)$ /blog-single?category=$1&id=$2 [L]
The extension is already removed by previous rule .
Moreover , your code should look like this :
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L,NC]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [L]
RewriteRule ^mcoh([^/]*)/([^/]*)$ /blog-single?category=$1&id=$2 [L,NE]
RewriteEngine on
RewriteRule ^/?mcohBlog/([^/d]+)/?$ blog-single.php?category=Blog&id=$1 [L,QSA]
Can you try this? Just add this rewriterule at the end of your code. and remove your last line of code
EDIT
Also your code organization is very wrong. That's why it's not working as expected
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L,NC]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [L]
RewriteRule ^/?mcohBlog/([^/d]+)/?$ blog-single.php?category=Blog&id=$1 [L,QSA]
This should be your last code
To redirect/rewrite
http://www.mcoh.co.in/blog-single?category=Blog&id=Janurary%202018%20Product%20training%20Score
to
http://www.mcoh.co.in/mcohBlog/Janurary%202018%20Product%20training%20Scores
put the following at the top of your htaccess file
RewriteEngine on
#To externally redirect /blog-single?category=foo&id=bar to /mochBlog/bar
RewriteCond %{QUERY_STRING} ^category=([^&]+)&id=(.+)$ [NC]
RewriteRule ^.*$ /mochBlog/%2? [R,L]
#To internally redirect /mochBlog/bar to /blog-single?category=foo&id=bar
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^mochBlog/(.+)$ /blog-single?category=blog&id=$1 [L]
How can I Hide index.php and rewriting URL parameters
http:example.com/www/index.php?page=admin&action=login
as
http:example.com/www/admin/login
I have hide index.php using the code mentioned below (Helped from URL) which makes URL as:
http:example.com/www/?page=admin&action=login
My htaccess file code
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]
But I need like this:
http:example.com/www/admin/login
If any body knows, that will be a great help.Thank you
You can use these rules in /www/.htaccess:
DirectoryIndex index.php
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /www/
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s(.*)/index\.php [NC]
RewriteRule ^ %1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([^/]+)/([^/]+)/?$ index.php?page=$1&action=$2 [L,QSA]
RewriteRule ^(.+)$ index.php?$1 [L,QSA]
My Site's every pages has Different URL with Seo variable, on page click URL becomes
index.php?seo=home
rates.php?seo=rates
reservation.php?seo=reservation
now i want to convert the URL to this
agnow.us/rates
agnow.us/information
agnow.us/reservation
Here is my .htaccess file.
Options +SymLinksIfOwnerMatch -Multiviews
RewriteEngine on
RewriteBase /
RewriteCond %{THE_REQUEST} \s/+rates\.php\?seo=([^\s&]+) [NC]
RewriteRule ^ /%1? [L,R=301]
RewriteRule ^/(.*)$ rates.php?seo=$1 [L,NC,QSA]
You can use this code in your root .htaccess:
Options +SymLinksIfOwnerMatch -Multiviews
RewriteEngine on
RewriteBase /
RewriteCond %{THE_REQUEST} \s/+rates\.php\?seo=([^\s&]+) [NC]
RewriteRule ^ /%1? [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/?$ rates.php?seo=$1 [L,NC,QSA]
I have this url:
http://www.website.co.uk/search.php?search=test&cat=catname
What I would like is:
http://www.website.co.uk/search/test/catname
I have tried this for the variables:
Options +FollowSymLinks
RewriteRule ^page/([^/]+)/?$ search.php?search=$1
and this to hide the php extension:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php[\s?] [NC]
RewriteRule ^ %1 [R=301,L]
and it doesnt seem to do anything
You can use this in root .htaccess:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteCond %{THE_REQUEST} \s/+search\.php\?search=([^\s&]+)&cat=([^\s&]+) [NC]
RewriteRule ^ /search/%1/%2? [R=302,L]
RewriteRule ^search/([^/.]+)/([^/.]+)/?$ /search.php?search=$1&cat=$2 [L,QSA,NC]
RewriteRule ^page/([^/]+)/?$ /search.php?search=$1 [L,QSA,NC]
I have a website where the url is localhost/project/profile.php?user=usernameand I am trying to get the url to look like this: localhost/project/username
The most I am able to do is get rid of the .php by using the following code:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L,NC]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [L]
but that is not what I need right now.
Here is the code that is meant to be changing the url - I got it off of another thread.
Options FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?user=$1 [L,QSA]
but it obviously doesn't work.
I need to be able to go to the url: localhost/project/username and it registers as the original URL localhost/project/profile.php?user=username
** THE ANSWER **
Thanks to Howlin
RewriteEngine On
RewriteCond %{THE_REQUEST} ^(GET|POST)\ /project/profile\.php\?user=(.*)\ HTTP
RewriteRule ^ /project/%2\? [R=301,L]
RewriteCond %{QUERY_STRING} !user=
RewriteRule ^(.*)$ /project/profile.php?user=$1 [L]
This should work:
RewriteEngine On
RewriteCond %{THE_REQUEST} ^(GET|POST)\ /project/profile\.php\?user=(.*)\ HTTP
RewriteRule ^ /project/%2\? [R=301,L]
RewriteCond %{QUERY_STRING} !user=
RewriteRule ^project/(.*)$ /project/profile.php?user=$1 [L]
The above will change project/profile.php?user=username to project/username and it will load the information from the project/profile.php?user=username page
EDIT:
RewriteEngine On
RewriteCond %{THE_REQUEST} ^(GET|POST)\ /project/profile\.php\?user=(.*)\ HTTP
RewriteRule ^ /project/%2\? [R=301,L]
RewriteCond %{QUERY_STRING} !user=
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /project/profile.php?user=$1 [L]
Try this:
Options FollowSymLinks
RewriteEngine On
RewriteBase /project/
RewriteRule ^([^/]+)/?$ profile\.php?user=$1 [L,NC,QSA]