i want change this URL:
domain.com/directory/news?id=80&title=news-title
to this:
hdomain.com/directory/news/news-title
how can I do this?
my htaccess also has a lot other rewrites. look:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /directory/
RewriteRule ^referenzen/([^.]+)/$ $1.php?rw=1 [QSA,L]
RewriteCond %{QUERY_STRING} !^rw=1
RewriteRule ^brands.php$ http://domain.com/directory/referenzen/brands/$1 [R=301,L]
RewriteRule ^referenzen/([^.]+)/$ $1.php?rw=1 [QSA,L]
RewriteCond %{QUERY_STRING} !^rw=1
RewriteRule ^entertainment.php$ http://domain.com/directory/referenzen/entertainment/$1 [R=301,L]
RewriteRule ^referenzen/([^.]+)/$ $1.php?rw=1 [QSA,L]
RewriteCond %{QUERY_STRING} !^rw=1
RewriteRule ^tourism.php$ http://domain.com/directory/referenzen/tourism/$1 [R=301,L]
RewriteCond %{THE_REQUEST} index(\\.php)?
RewriteRule ^index(\\.php)?$ http://domain.com/directory/ [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L,NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
I don't know if it's all correct but it is doing what it should do. ;-)
I only need the new rule to rewrite the dynamic url for the news.
Hope anyone can help - thanks!
You can rewrite all links to one php file and with reg. load templates that you need. I can help you.
Related
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]
hello all i have a site in which i would like to replace all the ? and = of urls by / .
i know this cn be done by htaccess file but i am very new to htaccess
i have this code in my htaccess file
ErrorDocument 404 /error404.php
ErrorDocument 403 /error404.php
Options -Indexes
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_METHOD} POST [NC]
RewriteRule ^ - [L]
RewriteCond %{HTTP_REFERER} !^http://(www\.)?domain.*$ [NC]
RewriteRule \.(gif|jpg|jpeg)$ http://www.domain.com [L]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{THE_REQUEST} \s/+(page1)\.php\?eid=(78)[&\s] [NC]
RewriteRule ^ /%1/%2? [R=301,L]
RewriteRule ^(page1)/(\d+)$ /$1.php?eid=$2 [L,QSA,NC]
RewriteCond %{THE_REQUEST} \s/+page2\.php\?url=([^\s&]+) [NC]
RewriteRule ^ /%1? [R=301,L]
RewriteCond %{THE_REQUEST} \s/+(.+?)\.php[\s?] [NC]
RewriteRule ^ /%1 [R=302,L,NE]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f [NC]
RewriteRule ^(.+?)/?$ /$1.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ /page2.php?url=$1 [L,QSA]
thnkx in advance ...
i wana replace all the ? and = of the url by /
like
domain.com/page.php?id=44 by
domain.com/page/id/4
First off, you need to clarify what you intend to accomplish.
If you intend to have the user visit domain.com/page/id/4 and have it internally be rewritten to page.php?id=4, then you have two options:
1) use a rewrite rule, such as:
RewriteRule ^/?page/([^/]+)/(.+)$ page.php?$1=$2
2) (preferred) use MultiViews and have your php script do the logic for you by parsing the
REQUEST_URI ($_SERVER['REQUEST_URI']).
First off, you need to clarify what you intend to accomplish.
If you intend to have the user visit domain.com/page/id/4 and have it internally be rewritten to page.php?id=4, then you have two options:
1) use a rewrite rule, such as:
RewriteRule ^/?page/([^/]+)/(.+)$ page.php?$1=$2
2) (preferred) use MultiViews and have your php script do the logic for you by parsing the
REQUEST_URI ($_SERVER['REQUEST_URI']).
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 trying to remove the php extension as well as hiding the sub directories using .htaccess file in my domain. However, I do not have much knowledge regarding regex and I am really stuck here. Would really appreciate if someone could assist with this!
What I'm trying to achieve is:
www.example.com/index.php to www.example.com/index
www.example.com/assets/php/company.php to www.example.com/company
CURRENT .htaccess FILE
Options +FollowSymLinks -MultiViews
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^assets/php/(.*)$ /$1 [L,NC,R=301]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [NC,L]
#To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L,NC]
</IfModule>
Currently, I could successfully remove the .php extension from the URL as well as achieving http://www.example.com/company but it displays a 404 Not Found Error. I believe I'm missing a RewriteCond line, but I do not know how to write it. Or do I require another htaccess file in /assets/php/?
Will really appreciate if someone could assist with this! Nevertheless, thanks for reading.
Cheers,
TY
You can have your rules like this in root .htaccess:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} /assets/php/([^.]+)\.php [NC]
RewriteRule ^ /%1 [L,NC,R=301]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/assets/php/$1\.php -f [NC]
RewriteRule ^([^.]+?)/?$ assets/php/$1.php [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f [NC]
RewriteRule ^([^.]+?)/?$ $1.php [NC,L]
USe This
RewriteEngine on
RewriteBase /
#enforce www subdomain
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} ^sitename.com [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
#forward all requests, except new/admin, to the 'new' directory without the user's awareness
RewriteRule new/admin - [S=2]
RewriteRule ^$ new/ [L]
RewriteRule (.*) new/$1 [L]
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.