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
Related
I have been trying to rewrite a url like this:
/gallery/test.php?id=1
to this:
/gallery/test/1
However it isn't working. I have url rewriting enabled and have used phpinfo() to check.
this is my code:
Options +FollowSymLinks -Multiviews
<IfModule mod_rewrite.c>
SetEnv HTTP_MOD_REWRITE On
RewriteEngine on
RewriteRule ^test/([0-9]+)/?$ test.php?id=$1 [NC,L]
</IfModule>
You probably need a rewrite base. Try adding the following on the line after the RewriteEngine on line.
RewriteBase /gallery/
this is a rewrite rule that should work
RewriteEngine On
RewriteRule ^gallery/test/([^/]*)$ /gallery/test.php?id=$1 [L]
Thanks
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'm trying to redirect URLs by using the .htaccess file:
index.php?i=Dengue-NS1-ELISA-kit---Antigen&id=682&cat=0
to
index.php?i=Dengue-NS1-ELISA-kit---Antigen&id=682&cat=17
Notice the 17 on the end there.
Here is the code that you need to put in .htaccess file under DOCUMENT_ROOT:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} ^(.*)(?:^|&)cat=0(&.*|)$ [NC]
RewriteRule ^index\.php$ index.php?%1%2&cat=17 [L,NC,R]
Here maybe you can use this tool I use it all the time http://www.htaccessredirect.net/
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]