/var/www/html/ is prepended to url
I am writing rewrite url
RewriteRule /news-tags-wiki/(.*)$ /news_tags_wiki.php?tag=$1 [L]
but /var/www/html is prepended to url
http://34.236.128.251/var/www/html/news-tags-wiki/vijay/
also trailing slash in appended
Related
I want to do a particular redirect
/mytag
redirect to file.php
the thing is it can be either /mytag/ or /mytag only without the final slash.
can't find this.. thanks
tried with this:
RewriteEngine on
options +FollowSymLinks
RewriteRule ^mytag(.*)$ file.php
As long as you don't have a file or directory called "mytag", then you can just end the regex with /? to make the ending slash optional:
RewriteRule ^mytag/?$ file.php [L]
Though what you already have should allow both the slash or no slash at the end. This won't work if you have a directory called mytag because mod_dir and DirectorySlash will always redirect a request for a directory that doesn't have a trailing slash to the same request with the trailing slash. If you have Multiviews turned on, and you happen to have a mytag.php (or something similar), mod_negotiation will kick in and the rewrite rule will get ignored.
I have directory structure like this:
public_html
.htaccess[1]
-apps
-.htaccess[2]
-admin
-myviwo
when I request http://localhost/mysite/admin it redirect me to http://localhost/mysite/apps/admin/ and shows me the content of the admin directory, if I request http://localhost/mysite/admin/ it doesn't redirect me but it shows me the content of admin directory again which is correct. But I want:
http://localhost/mysite/admin
http://localhost/mysite/admin/
Both of the above URLs shows me the content of admin directory without redirecting me.
.htaccess [1]
RewriteEngine On
RewriteBase /
RewriteRule (.*) apps/$1 [L]
.htaccess [2]
RewriteEngine On
RewriteBase /
RewriteRule ^admin/?(.*)$ admin/$1 [L]
RewriteRule ^(.*)$ myviwo/$1 [L]
How can I achieve this?
In the admin directory, add an htaccess file with the following:
DirectorySlash Off
This makes it so mod_dir won't redirect requests for the directory admin. However, note that there's an important reason why directory slash is "on" by default:
Security Warning
Turning off the trailing slash redirect may result in an information disclosure. Consider a situation where mod_autoindex is active (Options +Indexes) and DirectoryIndex is set to a valid resource (say, index.html) and there's no other special handler defined for that URL. In this case a request with a trailing slash would show the index.html file. But a request without trailing slash would list the directory contents.
If that's ok with you, then that's all that you need.
Otherwise, you may need to add a special rule specifically for admin. In the .htaccess[1] file, add right below the rewrite base:
RewriteRule ^admin$ apps/admin/ [L]
EDIT: to make the above rule dynamic, you need to first check if it's a directory:
RewriteCond %{DOCUMENT_ROOT}/apps%{REQUEST_URI} -d
RewriteRule ^(.*[^/])$ apps/$1/ [L]
I have duplicate urls and i need to do some redirection in htaccess
Examples:
Original Urls are :
www.mywebsite.com/listofgames/pacman.html
www.mywebsite.com/listofgames/nintendo.html
www.mywebsite.com/listofgames/snake.html
I have about 1000 games name
Example of duplicate urls :
www.mywebsite.com/listofgames/1/pacman.html
www.mywebsite.com/listofgames/1521/pacman.html
www.mywebsite.com/listofgames/52154/pacman.html
www.mywebsite.com/listofgames/abc/pacman.html
www.mywebsite.com/listofgames/opq/pacman.html
www.mywebsite.com/listofgames/opq/1/2/35/pacman.html
www.mywebsite.com/listofgames/154/3562/snake.html
www.mywebsite.com/listofgames/2541/snake.html
www.mywebsite.com/listofgames/524/snake.html
www.mywebsite.com/listofgames/absc/gtar/15/nintendo.html
www.mywebsite.com/listofgames/nije/nintendo.html
I need to redirect them to original urls
So
www.mywebsite.com/listofgames/anynumber/mygamesname.html
www.mywebsite.com/listofgames/anyword/mygamesname.html
www.mywebsite.com/listofgames/anyword/anynumber/anyword/mygamesname.html
Must be redirected to
www.mywebsite.com/listofgames/mygamesname.html
You may try this:
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/listofgames/.*/([^\.]+)\.html/? [NC]
RewriteRule .* listofgames/%1.html [R=301,L]
Redirects permanently
http://www.mywebsite.com/listofgames/any/number/of/folders/mygamesname.html
with or without trailing slash.
To:
http://www.mywebsite.com/listofgames/mygamesname.html
Effectively removing the segment path between /listofgames/ folder and the HTML file.
String listofgames and extension html are assumed to be fixed, while mygamesname is assumed to be variable.
The incoming URL structure has to be kept for the rule-set to work: Last string inside the URL must be the HTML file.
For silent mapping, remove R=301 from [R=301,L]
RewriteEngine on
RewriteRule ^$ http://my-site.com/directory [R=301,L]
This redirects my root page to
http://my-site.com/directory/
(notice the trailing slash).
How can I make .htaccess omit the trailing slash when generating the URL?
This is because directory is an existing directory, this is not a rewritten url.
Use another word instead of :
RewriteEngine on
RewriteRule ^$ /mypath [R=301,L]
RewriteRule ^mypath$ /directory/ [L]
Quote from noupe.com :
The filesystem on your server will always take precedence over the
rewritten URL. For example, if you have a directory named “services”
and within that directory is a file called “design.html”, you can’t
have the URL redirect to “http://domain.com/services”. What happens is
that Apache goes into the “services” directory and doesn’t see the
rewrite instructions.
To fix this, simply rename your directory (adding an underscore to the
beginning or end is a simple way to do that).
Bonus : To remove trailing slash in every urls :
RewriteEngine On
RewriteRule ^(.*)/$ $1 [R,301,L]
I am having trouble with some rewrite rules on an updated site...I am trying to redirect requests for old directories to new pages, like this:
http://www.mysite.com/olddirectory --> http://www.mysite.com/this-is-the-new-page
the following rule works, but not with a trailing slash on the directory:
ie: /olddirectory redirects correctly, but /olddirectory/ doesn't
RewriteRule ^olddirectory$ this-is-the-new-page [R=301,NC,L]
Any ideas on how to get it to recognise the trailing slash on the dir?
The following rule will do redirect with or without trailing slash:
RewriteRule ^olddirectory/?$ /this-is-the-new-page [NC,R=301,L]
The key is to make trailing slash optional, and that's what ? does: /?