This url
example.com/videos/load.php?cat=video-category
would become
example.com/videos/video-category
Also, there is pagination url
example.com/videos/load.php?cat=video-category&p=2
and it would become
example.com/videos/video-category/page/2
I tried to do this.. but it doesn't work.
Here is my htaccess (into videos folder)
Options +FollowSymLinks
RewriteEngine On
RewriteBase /videos/
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,NE,L]
RewriteRule ^(\w+/+/)page/?$ $1 [R=301,L]
RewriteRule ^(\w+)(?:/[^/]+)?/?$ load.php?cat=$1 [L,QSA]
RewriteRule ^(\w+)/[^/]+/([0-9]+)/?$ load.php?cat=$1&p=$2 [L,QSA]
Put this code in your htaccess.
This should work
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]
Related
I am new to web development.
Below Htaccess code works fine in root directory files. While We try to rewrite the files in sub folder /test/downloadh.php. when i was changed below code will we can't get the root files links are notworking.
RewriteEngine on
RewriteBase /test/
Would you please suggest us, how to get the url
http://example.com/test/downloadh/the-house-on-the-borderland
to
http://example.com/test/downloadh.php?id=the-house-on-the-borderland
Working Code:-
# disable directory browsing
Options -Indexes
AddDefaultCharset UTF-8
FileETag MTime Size
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+album\.php\?Id=([^\s&]+) [NC]
RewriteRule ^ album/%1? [R=301,L]
RewriteRule ^album/([^/]+)/?$ album.php?Id=$1 [L,QSA]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+download\.php\?id=([^\s&]+) [NC]
RewriteRule ^ download/%1? [R=301,L]
RewriteRule ^download/([^/]+)/?$ download.php?id=$1 [L,QSA]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+downloada\.php\?linkb=([^\s&]+) [NC]
RewriteRule ^ downloada/%1? [R=301,L]
RewriteRule ^downloada/([^/]+)/?$ downloada.php?linkb=$1 [L,QSA]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(?:downloadb\.php)?\?mlink=([^\s]+)&linkb=([^\s]+)? [NC]
RewriteRule ^ downloadb/%1%2? [R=301,L]
RewriteRule ^downloadb/([^/]+)/([^/]+)/?$ downloadb.php?mlink=$1&linkb=$2 [L,QSA]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(?:songs\.php)?\?id=([^\s]+)&linkb=([^\s]+)? [NC]
RewriteRule ^ songs/%1/%2? [R=301]
RewriteRule ^songs/([^/]+)/([^/]+)/?$ songs.php?id=$1&linkb=$2 [L,QSA]
# CUSTOM ERRORPAGE
ErrorDocument 401 /error/test.php
ErrorDocument 403 /error/test.php
ErrorDocument 404 /error/test.php
ErrorDocument 500 /error/test.php
Error Code:-
RewriteCond %{THE_REQUEST} /downloadh(?:\.php)?\?id=([^\s&]+)\s [NC]
RewriteRule ^ downloadh/%1/? [R=302,L,NE]
RewriteRule ^downloadh/([^/]+)/?$ downloadh.php?id=$1 [NC,L,QSA]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /test/downloadh.php\?id=([^\s&]+) [NC]
RewriteRule ^test/downloadh\.php /%1? [R=301,L,NE]
RewriteRule ^downloadh/([^/]+)/?$ /test/downloadh.php?id=$1 [L,QSA]
Try this code :
RewriteCond %{THE_REQUEST} ^[A-Z]{3,7}\s/(test/downloadh)\.php\?id=(.+)\sHTTP.*$ [NC]
RewriteRule ^ %1/%2? [L,R=301]
RewriteRule ^test/downloadh/([^/]+)/?$ test/downloadh.php?id=$1 [L]
I have a htaccess file in root and another htaccess in films folder. I want to stop all the rewrite urls or conditions to affect the films folder. I have some other rules in film folder htaccess.
My root htaccess looks like this
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^abc\.in$ [NC]
RewriteRule ^(.*)$ http://www.abc.in/$1 [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
My sub directory films folder htaccess
Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteBase /films/
RewriteCond %{REQUEST_METHOD} =POST
RewriteRule ^ - [L]
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
RewriteRule ^change-password/$ changepassword.php
RewriteRule ^change-password$ changepassword.php
The above code is just a glimpse of my original htaccess
You can do it by following code :-
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/films/$1 [R=301,L]
It may help you.
In /films/.htaccess ,Change your rule
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
to this :
RewriteRule ^(.*)$ http://%1/films/$1 [R=301,L]
To redirect all /films requests to www, you can use something like the following :
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]
I want redirect this urls:
http://tops.domain.com/test
http://files.domain.com/css/style.css
http://domain.com/test
to these:
/tops.php?what=test
/css/style.css
/index.php?username=test
I written this codes in .htaccess file and put it in root:
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^tops\. [NC]
RewriteRule .* tops.php?what=$0 [QSA,L,NC]
RewriteCond %{HTTP_HOST} ^files\. [NC]
RewriteRule .* $0 [NC,L,QSA]
RewriteRule .+ index.php?username=$0 [L,QSA]
but not work right
Use this .htaccess :
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^files\. [NC]
RewriteRule ^ - [L]
RewriteCond %{HTTP_HOST} ^tops\. [NC]
RewriteCond %{REQUEST_URI} !^/tops\.php [NC]
RewriteRule .* tops.php?what=$0 [QSA,L,NC]
RewriteCond %{QUERY_STRING} !^username= [NC]
RewriteRule .+ index.php?username=$0 [L,QSA]
I provided this .htaccess:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.lebmotors.com/new/
RewriteRule (.*) http://www.lebmotors.com/new/$1 [R=301,L]
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)$ moreprod.php?id=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ moreprod.php?id=$1
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)/([0-9]+)$ moreprod.php?id=$1&topid=$2
RewriteRule ^([a-zA-Z0-9_-]+)/([0-9]+)/$ moreprod.php?id=$1&topid=$2
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)/([0-9]+)$ moreprod.php?id=$1&topid=$2&catid=$3
RewriteRule ^([a-zA-Z0-9_-]+)/([0-9]+)/$ moreprod.php?id=$1&topid=$2&catid=$3
Still it does not work
I get: http://www.lebmotors.com/new/moreprod.php?id=107&topid=4&catid=8
What AM I doing wrong
Many Thanks
First of all, you don't need to repeat RewriteEngine On directive.
Then, when you add your rules, you still can access your pages via moreprod.php (but you can also access it from new clean url).
Here's how your htaccess should look like, assuming moreprod.php is also in new folder
Options -MultiViews
RewriteEngine On
RewriteBase /new/
RewriteCond %{THE_REQUEST} /moreprod\.php\?id=([^&\s]+)\s [NC]
RewriteRule . moreprod/%1/? [R=301,L]
RewriteCond %{THE_REQUEST} /moreprod\.php\?id=([^&\s]+)&topid=([^&\s]+)\s [NC]
RewriteRule . moreprod/%1/%2/? [R=301,L]
RewriteCond %{THE_REQUEST} /moreprod\.php\?id=([^&\s]+)&topid=([^&\s]+)&catid=([^&\s]+)\s [NC]
RewriteRule . moreprod/%1/%2/%3/? [R=301,L]
RewriteCond %{THE_REQUEST} /morenews\.php\?id=([^&\s]+)\s [NC]
RewriteRule . morenews/%1/? [R=301,L]
RewriteRule ^morenews/([^/]+)/$ morenews.php?id=$1 [L]
RewriteRule ^moreprod/([^/]+)/$ moreprod.php?id=$1 [L]
RewriteRule ^moreprod/([^/]+)/([^/]+)/$ moreprod.php?id=$1&topid=$2 [L]
RewriteRule ^moreprod/([^/]+)/([^/]+)/([^/]+)/$ moreprod.php?id=$1&topid=$2&catid=$3 [L]
With this code, if you try (for example) to reach http://domain.com/new/moreprod.php?id=123&topid=456&catid=789 then you'll redirect to http://domain.com/new/moreprod/123/456/789/
Conclusion
You can now access your pages via clean urls like
http://domain.com/new/moreprod/123/ (id=123)
http://domain.com/new/moreprod/123/456/ (id=123 and topid=456)
http://domain.com/new/moreprod/123/456/789/ (id=123 and topid=456 and catid=789)
Resolved, just moved these lines to the bottom of .htaccess
RewriteEngine On
RewriteBase /new/
....
RewriteCond %{THE_REQUEST} /moreprod\.php\?id=([^&\s]+)\s [NC]
RewriteRule . moreprod/%1/? [R=301,L]
.....
RewriteCond %{THE_REQUEST} /moreprod\.php\?id=([^&\s]+)&topid=([^&\s]+)&catid=([^&\s]+)&cagid=([^&\s]+)\s [NC]
RewriteRule . moreprod/%1/%2/%3/%4/? [R=301,L]
RewriteRule ^moreprod/([^/]+)/$ moreprod.php?id=$1 [L]
.....
RewriteRule ^moreprod/([^/]+)/([^/]+)/([^/]+)/([^/]+)/$ moreprod.php?id=$1&topid=$2&catid=$3&cagid=$4 [L]
# THIS TO THE BOTTOM
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [L]
I have the following problem:
http://www.mydomain.com/articles.php?artid=89
should become: http://www.mydomain.com/mykeyword
I dont mind if the id remain in the url...like: http://www.mydomain.com/89/mykeyword
I have the following .htaccess for the moment:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(mydomain\.com)$ [NC]
RewriteRule ^(.*)$ http://www.%1/$1 [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+news\.php [NC]
RewriteRule ^ mykeyword [R=301,L]
RewriteRule ^mykeyword/?$ news.php [L,NC]
The above part works like a charm.
Any help will be deeply appreciated.
Regards, Zoran
Append these rule at the bottom of your .htaccess:
RewriteEngine On
RewriteBase /turkexpo/
RewriteCond %{HTTP_HOST} ^(webone\.gr)$ [NC]
RewriteRule ^(.*)$ http://www.%1/turkexpo/$1 [R=302,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+turkexpo/news\.php [NC]
RewriteRule ^ mykeyword [R=302,L]
RewriteRule ^mykeyword/?$ news.php [L,NC]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+turkexpo/articles\.php\?artid=([0-9]+) [NC]
RewriteRule ^ %1/mykeyword? [R=302,L]
RewriteRule ^([0-9]+)/mykeyword/?$ articles.php?artid=$1 [L,NC,QSA]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+turkexpo/companies\.php\?fairid=([0-9]+)&ehallid=([0-9]+) [NC]
RewriteRule ^ companies/%1/%2? [R=302,L]
RewriteRule ^companies/([0-9]+)/([0-9]+)/?$ companies.php?fairid=$1&ehallid=$2 [L,NC,QSA]
This will forward a URI of /89/mykeyword to /articles.php?artid=89 and externally redirect the opposite of it.
Once you make sure it is working change R=302 to R=301.