I can make the following URL:
example.com/video1
redirect to:
example.com/video/video1.php
but I would like it to display:
example.com/video1
in the browser but it is not.
It is displaying:
example.com/video/video1.php
And when I go to URL:
example.com/video/video1.php
it should display
example.com/video1
in the browser but it is displaying:
example.com/video/video1.php
How do I do this?
Here is what I am using:
RewriteEngine On
RewriteRule ^video1 /videos/video1.php [QSA,NC,L]
RewriteRule ^/videos/video1.php /video1 [R=301,L]
You can use the following rules in /root/.htaccess
RewriteEngine on
#1--Redirect from "/videos/foo.php" to "/foo"--#
RewriteCond %{THE_REQUEST} /videos/([^.]+)\.php [NC]
RewriteRule ^ /%1 [NE,NC,L,R]
#2--Internally map "/foo" to "/videos/foo.php--#
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ /videos/$1.php [NC,L]
Clear your browser's cache before testin this.
Have you tried
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^yoursite.com
RewriteRule (.*) http://www.yoursite.com/$1 [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9} /index.html HTTP/
RewriteRule ^index.html$ http://www.yoursite.com/ [R=301,L]
Source:
https://www.branded3.com/blog/htaccess-mod_rewrite-ultimate-guide/
You forgot to add closing $ in your regex.
Please try this:
RewriteEngine On
RewriteRule ^/video1$ /videos/video1.php [QSA,NC,L]
RewriteRule ^/videos/video1.php$ /video1 [R=301,L]
instead of
RewriteEngine On
RewriteRule ^video1 /videos/video1.php [QSA,NC,L]
RewriteRule ^/videos/video1.php /video1 [R=301,L]
Related
We have the following file structure in our ftp account.
/index.php
/views/account/users/index.php
/views/account/clients/index.php
/views/profile/index.php
/views/settings/index.php
....
Which means that the urls is as follows:
www.thesite.com/
www.thesite.com/views/account/users/
www.thesite.com/views/account/clients/
www.thesite.com/views/profile/
www.thesite.com/views/settings/
...
What we need, is to remove views from all possible variations, so that we can link to, or enter the following url in the browser's address bar.
www.thesite.com/account/users/
Any help would be greatly appreciated.
Try these rules in your site root .htaccess:
RewriteEngine on
RewriteCond %{THE_REQUEST} \s/+views/(\S*)\s [NC]
RewriteRule ^ /%1 [NE,L,R=302]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^((?!views/).+)$ views/$1 [NC,L]
You can use the following Rules in Root/.htaccess :
RewriteEngine on
#/foo to /views/foo
RewriteCond %{THE_REQUEST} /views/([^/.\s]+) [NC]
RewriteRule ^ /%1 [NC,L,R]
RewriteRule ^([^/.]+)/?$ /views/$1 [NC,L]
#Rewrite /foo/bar to /views/foo/bar
RewriteCond %{THE_REQUEST} /views/([^/]+)/([^/.\s]+) [NC]
RewriteRule ^ /%1/%2 [NC,L,R]
RewriteRule ^([^/]+)/([^/.]+)/?$ /views/$1/$2 [NC,
This url
example.com/videos/load.php?cat=video-category
would become
example.com/videos/video-category
Also, there is pagination and limit url
example.com/videos/load.php?cat=video-category&p=2&limit=20
and it would become
example.com/videos/video-category?page=2&limit=20
this url also work
example.com/videos/video-category?page=2
example.com/videos/video-category?limit=20
Here is my htaccess (into videos folder)
Options +FollowSymLinks
RewriteEngine on
RewriteBase /videos/
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,NE,L]
RewriteRule ^([^/]+)/?$ load.php?cat=$1 [L,QSA]
RewriteRule ^([^/]+)/page/?$ $1 [R=301,L]
RewriteRule ^([^/]+)/page/([1-9][0-9]*)$ load.php?cat=$1&p=$2 [L,QSA]
how to do this.. plz help me.. thanks..
Think maybe you're looking for something like this?
Options +FollowSymLinks
RewriteEngine on
RewriteBase /videos/
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,NE,L]
RewriteCond %{THE_REQUEST} \ /+videos/load\.php\?cat=([^&\ ]+)&?([^\ ]*)
RewriteRule ^ %1?%2 [L,R]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ load.php?cat=$1 [L,QSA]
That satisfies the question you're asking, but your rules have stuff for /page/, which isn't part of your question at all.
I am wondering how to rewrite this url profile.php?user=1 to /user/1.
I know that this can be done by .htaccess. Here is what i have tried and it worked fine but the only problem is that it
RewriteCond %{THE_REQUEST} \s/+profile\.php\?user=([^\s&]+) [NC]
RewriteRule ^ /%1? [R=302,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/?$ profile.php?user=$1 [L,QSA]
Besides these codes, my .htacces also has these lines
RewriteEngine On
RewriteCond %{HTTP_REFERER} !^http://(www\.)?domain.*$ [NC]
RewriteRule \.(gif|jpg|png)$ http://www.domain.com [L]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
ErrorDocument 404 /error404.php
ErrorDocument 403 /error404.php
Options -Indexes
RewriteCond %{THE_REQUEST} \s/+page\.php\?pagename=([^\s&]+) [NC]
RewriteRule ^ /%1? [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ /page.php?pagename=$1 [L,QSA]
Please also tell me if my .htaccess page is correct. I am not good at htaccess
Change this:
RewriteCond %{THE_REQUEST} \s/+profile\.php\?user=([^\s&]+) [NC]
RewriteRule ^ /%1? [R=302,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/?$ profile.php?user=$1 [L,QSA]
to:
RewriteCond %{THE_REQUEST} \s/+profile\.php\?user=([^\s&]+) [NC]
RewriteRule ^ /user/%1? [R=302,L]
RewriteRule ^user/([^/]+)/?$ profile.php?user=$1 [L,QSA]
And make sure the page has either absolute links or add this to the page's header:
<base href="/" />
otherwise, all your links will be broken.
In htacess rewrite you want to in fact redirect a url structure to a different url
If you have a link to profile.php?user=1 you will have to change this like to this : profile.php/user/1 then tell your htacess to redirect this adresse to this profile.php?user=1
You can do this :
RewriteRule ^user/(.*)$ index.php?&user=$1
If you want to test out some htaccess I will recomande this usedul site : http://htaccess.madewithlove.be/
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]
So I'm trying to turn my website from this:
http://profe5.com/Profe5-Web/public_html/login.html
To this:
http://profe5.com/login
I've been struggling to do this, but whenever I run it I get 404 error!
This is my htaccess:
DirectoryIndex Profe5-Web
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^profe5\.com$ [NC]
RewriteRule ^(.*)$ http://profe5.com/$1 [R=301,L]
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^([^\.]+)$ $1.html [R=301,L]
RewriteRule ^Profe5-Web/public_html/(.*)$ $1 [R=301,L]
It would be so awesome if you guys could help me!
Thanks so much!
This should be your complete .htaccess:
DirectoryIndex Profe5-Web
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^profe5\.com$ [NC]
RewriteRule ^(.*)$ http://profe5.com/$1 [R=301,L]
# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+Profe5-Web/public_html/([^.]+)\.html [NC]
RewriteRule ^ %1? [R=301,L]
# internal forward from pretty URL to actual one
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^([^/.]+)/?$ Profe5-Web/public_html/$1.html [L,QSA]
you might consider instead doing this via a virtual host; check with your hosting company about setting it up
If you want /login to map to Profe5-Web/public_html/login.html - try this:
RewriteRule ^([^.]+)$ Profe5-Web/public_html/$1.html [R=301,L]
The RewriteRule you already have, RewriteRule ^([^\.]+)$ $1.html [R=301,L] will map /login to /login.html, which doesn't seem to do what you need it to.