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.
Related
suppose, I have an index100.php file inside folder1 (eg. folder1/index100.php). Is there any way so that if the user types folder1/index.php, then it will automatically redirect to folder1/index100.php?
How can it be done using .htaccess file?
If you want to show index100.php insted of index.php as your directory handler, you can use DirectoryIndex directive in /folder1htaccess
DirectoryIndex index100.php
This will serve you the /index100.php if you visit http://example.com/folder1
If you actually want to redirect /folder1/index.php to /folder1/index100.php then use the following rule in your /folder1/. htaccess .
RewriteEngine on
RewriteRule ^index\.php$ /folder1/index100.php [L,R]
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.
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]
I have this url:
http://mysite.com/home.php?name=username
I want to be able to access that by going to:
http://mysite.com/home/username
Is there a way to do that?
You can do this using the mod_rewrite extention that comes with Apache.
Create a new .htaccess file in your web root directory, and populate it with the following text.
RewriteEngine On
RewriteRule ^home/([^/]*)$ home.php?name=$1 [L]