I Got this URL
http://localhost/test/test.php/1
This is I want to
http://localhost/test/test.php?a=1
test.php
echo $_GET['a'];
How to write .htaccess rule for it?
RewriteEngine On
RewriteRule ^test/test\.php/(\d+)$ /test/test.php?a=$1 [L]
Put this in htaccess file and place it in the document root directory of apache.
Related
I want to rewrite domain.com/pages/welcome.php
to domain.com/welcome using htaccess under apach2.
In .htaccess in the document root ,add this :
RewriteEngine on
RewriteRule ^pages/welcome/?$ /pages/welcome.php [L]
This will allow you to access welcome.php file without its extension.
I have some files with .exe extension in subfolder /files/
I would like to redirect all queries
/files/somename.exe
to
/script.php?name=somename
Also I have a root .htaccess and local .htaccess in /files/ folder.
I think I should change local .htaccess, but it doesn't work.
what i tried -
RedirectMatch ./([_A-Za-z0-9-]+).exe$ /script.php?name=$1
Please help!
You can use this rule:
RedirectMatch 302 ^/files/([_A-Za-z0-9-]+)\.exe$ /script.php?name=$1
OR if you want internal rewrite only then put this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteBase /
RewriteRule ^files/([\w-]+)\.exe$ script.php?name=$1 [L,NC,QSA]
I have very specific question, I want to solve it using .htaccess and mod_rewrite, I want to make rule in .htaccess file using mod_rewrite, so when somebody visit my site ex.
mysite.com , mysite.com/css/style.css file should be read from other location mysite.com/version1/css/style.css, if I say it otherwise, style.css should not be "picked up" from root folder, but sub-folder.
Try adding this to the htaccess file in your document root:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?mysite\.com$ [NC]
RewriteRule ^css/(.*)\.css$ /version1/css/$1.css [L]
We took over a website with about a kabillion pages in the old site root directory done in htm that need to be retired. I want to do a 301 redirect from the pages to the index.php in the root directory of the new site using a wildcard. An example of the page naming structure follows:
oldpage_dees.htm
oldPage_dat.htm
oldPage_deeudderting.htm
and so on. As stated, I need them redirected to the index.php in the root directory. Going by examples and discussions here I've tried:
RewriteEngine On
RewriteRule ^/oldpage_([\w]*).htm$ /index.php [R=301,L]
but I get a 404 error.
Any suggestions? Thanks in advance!
As .htaccess is directory level configuration file, you don't need to specify forward slash, I think this will do the job:
RewriteEngine On
RewriteRule ^oldpage_([\w]*).htm$ index.php [R=301,L]
Meanwhile, you can use the following .htaccess tester to debug your rewrite rules.
I'd like to know the RewriteRule to redirect(301) every index.php to their root.
For example, this url:
http://www.example.com/folder/index.php
is redirected to:
http://www.example.com/folder/
I need a generic rule to avoid .htaccess edit for each new folder.
The .htaccess will be placed on the root of the website.
RewriteEngine On
RewriteRule ^(.*)/?index\.php(\?*.*)$ $1/$2 [L,R=301]
This should take /anyfolder/another/folder/index.php?a=1 and rewrite it to /anyfolder/another/folder/?a=1 (GET variables optional, of course.)