Basically all I want to do is this:
I have a URL to a PDF files on the server in this location:
http://chudz.co.uk/philaletheians.co.uk/Study%20notes/Atlantean%20Realities/Atlantis'%20study%20-%20Appendices%20and%20Notes.pdf
Now I want to remove this section of the URL:
/Study%20notes/Atlantean%20Realities/
This is what I have done in my htaccess file and it does not work:
Options +FollowSymlinks
RewriteEngine On
RewriteRule ^/ /Study%20notes/Atlantean%20Realities/
I am new to this! as you can probably see above :) I have to keep the directory layout on the server as it is so my only option is to use mod_rewrite maybe?
Try adding the following to your .htaccess file in the root folder of your domain
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
#if request does not already start with /Study notes/Atlantean Realities/
RewriteCond %{REQUEST_URI} !^/Study\ notes/Atlantean\ Realities/ [NC]
#rewrite it to the /Study%20notes/Atlantean%20Realities/ directory
RewriteRule (.*) /Study\ notes/Atlantean\ Realities/$1 [L]
Related
I want to redirect every requests to my public/index.php file. i've tried
RewriteEngine On
RewriteRule ^(.*)$ public/index.php?url=$1
code that seems fine but its not working. my goal is change url form http://example.com/?url=user/profile/2 to http://example.com/user/profile/2.
my directory structure is
root
public
index.php
vendor
.htaccess
composer.json
To handle URLs like: http://example.com/user/profile/2 please try following Rules sets in your .htaccess file. Place your htaccess rules file into root directory. Please make sure to clear your browser cache before testing your URLs.
Options -MultiViews
RewriteEngine ON
RedirectBase /ApadanaCMS/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)/([^/]*)/(.*)/?$ public/index.php?url=$1/$2/$3 [L]
OR try following rules, please make sure either try above OR following rules at a time only.
Above will work for non-existing pages, to make it for any url(like you mentioned in your question) try:
Options -MultiViews
RewriteEngine ON
RedirectBase /ApadanaCMS/
RewriteCond %{REQUEST_FILENAME} !index\.php [NC]
RewriteRule ^([^/]*)/([^/]*)/(.*)/?$ public/index.php?url=$1/$2/$3 [L]
heres the solution:
uncoment (remove # ) mod_rewrite.so module in httpd.conf file in apache2 (in my case c:\Apache24\conf\httpd.conf) file. also change AllowOverride none to AllowOverride All in that file under DocumentRoot "${SRVROOT}/htdocs" section.
and this is .htaccess content
RewriteEngine on
RewriteRule ^(.*)$ public/index.php?url=$1 [QSA,L]
RewriteRule ^()$ public/index.php?url=$1 [QSA,L]
however if you need to get static files in your static directory add a new .htaccess file inside static directory with RewriteEngine off content
I just transfered my Domain to a new Server. Mod_Rewrite is enabled on the new server but unfortunately some RewriteRules don't work, while others do. I haven't changed anything in the .htaccess
So the URL www.mydomain.com/go/10.html should make an internal redirect to www.mydomain.com/go.php?name=10
The snippet in the .htaccess looks like this:
# go.php
RewriteRule ^go$ "$0/" [R=301,L,QSA]
RewriteRule ^go/$ go.php [L,QSA]
RewriteRule ^go/.*?([^\.\/]*)\.html$ go.php?name=$1 [L,QSA]
The $_GET["name"] is not available if I call this url.
Replace your .htaccess code with this.
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^(go)/([^.]+)\.html$ /$1.php?name=$2 [L,QSA,NC]
I have a file path that looks like this: /cgi-bin/folder/script.cgi?t=1&u=http://domain.com/url/url-2/
What I want to do is create a rewrite rule to pull the querystring u= and then redirect to that URL, I've been working for a while on this with no success.
RewriteRule ^cgi-bin/folder/script.cgi?t=1&u=(.*)$ $1 [R=301,L]
Above is an example of one of my "solutions" that obviously didn't work. Any help is much appreciated. Thanks!
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+cgi-bin/folder/script\.cgi\?t=1&u=([^\s&]+) [NC]
RewriteRule ^ /%1 [R=302,L,NE]
I have a page name page.php and my url as localhost/mysite/page.php , now how can i change the url using .htaccess file to localhost/mysite/somethinghere1/somethinghere2/page.php
It tried using the below code but it doesn't work out.
<IfModule mod_rewrite.c>
# Enable Rewriting
RewriteEngine On
# Rewrite user URLs
# Input: user/NAME/
# Output: user.php?id=NAME
RewriteRule ^somethinghere1/somethinghere2/.php? page.php
</IfModule>
how can i acheive this.
What about this:
RewriteRule ^somethinghere1/somethinghere2/([^/\.]+).php/?$ page.php
Use it like this:
RewriteRule ^(mysite/)somethinghere1/somethinghere2/(.*\.php)/?$ $1$2 [L,NC]
Also make sure this in .htaccess file in your DOCUMENT_ROOT directory.
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^([^/]+)/([^/]+)/page.php /page.php?first=$1&second=$2 [NC]
This is the basic code , you can play with it to fit your needs like the following edit :
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^([^/]+)/([^/]+)/([^/]+) /$3.php?first=$1&second=$2 [NC]
So x/y/z would be z.php?first=x&second=y
I have created a site in a subdirectory and would like the site to appear as if it's in the root.
I used the below Mod_Rewrite code to get the site root to redirect to the subdirectory, but I would like the folder the files are held in to not appear.
currently: www.example.com/sitefiles/content/
Would like: www.example.com/content
Thanks
Options +FollowSymlinks -MultiViews
RewriteEngine on
RewriteBase /
RewriteRule ^$ /sitefiles/ [L]
RewriteRule (.*) /sitefiles/$1 [L]
If it needs to be done via .htaccess and mod_rewrite, then use this:
Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/sitefiles/
RewriteRule (.*) /sitefiles/$1 [L]
Since you do not explicitly specify the page when website root will be hit, then there is no need for this line: RewriteRule ^$ /sitefiles/ [L]
You need to add condition for your main rewrite rule to prevent rewrite loop (when already rewritten URL gets rewritten again): RewriteCond %{REQUEST_URI} !^/sitefiles/
Well, the directory should have no reason to appear in any listing, and that mod_rewrite you posted should allow you to do as you said. Still, I would go about it a different way:
Options +FollowSymLinks +Indexes
RewriteEngine on
RewriteBase /
RewriteRule ^$ sitefiles/ [L]
RewriteRule ^(.+)$ sitefiles/$1 [L]
Hope this works.