.htaccess PHP Rewrite Rules - mod-rewrite

I have this .htaccess file and it worked perfectly
RewriteEngine On
RewriteBase /
RewriteRule ^([\w-]+)\.html$ index.php?ID=$1
http://example.com/ipad.html
but i have a problem when the the url ( id) Contains slashes
for example
id=1/4ABCD Which gives this url (http://example.com/1/4ABCD.html)
Please how resolve this problem?

Related

How to mod-rewrite the url with custom extension

I need to change the pattern of my url from the normal path into a subdomain. I tried write the .htaccess but it's not work.
http://hello.com/sos/article.php?id=1&title=this-is-a-title.php
From the url above I want to:
Change the pattern to call the page so I remove sos before the domain as a subdomain. So I'd got http://sos.hello.com/
I need the variable to be replaced with forward slash and suffixed with .sos. As the story is about warning : article/1/this-is-a-title.sos
I wish I could have something like this:
http://sos.hello.com/article/1/this-is-a-title.sos
So I wrote :
RewriteEngine On
RewriteRule ^article/([^/]*)/([^/]*)\.sos$ /article.php?id=$1&title=$2 [L]
And guess what! It's not work. Please point me out. What I've done wrong???
I've got the answer after several tries:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.hello.com
RedirectMatch 301 ^/sos/$ http://sos.hello.com/mypage.php
RewriteRule ^article/([^/]*)/([^/]*)\.sos$ /article.php?id=$1&title=$2 [L]
save as .htaccess to the subdomain directory

mod Rewrite : Hide php extension & replace variable name by slash

Need help, It is basic Mod-Rewrite. But i am confused
My current URL:
http://example.com/category.php?fn=accounting-tax
Want look like this:
http://example.com/category/accounting-tax
Only Apache Mod-Rewrite, No PHP please
Update:
Is it possible without PHP?
Thank you
Add this to your .htaccess in your web root /
RewriteEngine on
RewriteBase /
RewriteCond %{QUERY_STRING} (^|&)fn=(.*)(&|$)
RewriteRule ^category\.php$ category/%2 [NC,L]
Assuming, you meant
/category.php?fn=accounting-tax should take you to /category/accounting-tax
without showing up on the address bar. If you want an external redirect use [R=301,NC,L] instead.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^category/([a-z0-9\-]+)/item/?$ /category.php?id=$1
</IfModule>

Mod rewrite whit multipe variables

My .htaccess is in test and I have added the folowing commands.
Options +FollowSymLinks +Indexes
RewriteEngine on
RewriteBase /
RewriteRule ^Categorie/([^.]+)$ test/index.php?p=$1 [L]
If I check p in the index whit the url domain.com/test/Categorie/1
I get demo1.
If I do domain.com/test/Categorie/1/somename/
I get a 404 error.
Everywhere on the internet I find this solution for my problem but stangly enough I can not get it working because I keep getting this problem.
RewriteRule ^c([0-9]+).*\.html test/index.php?c=$1
is what I used to fix it.

HTML rewrite .htaccess file

When I used the .htaccess file in to my root folder to rewrite the URL
it occurs error & got this massage " The server encountered an internal error or misconfiguration and was unable to complete your request."
I am using this rewrite rule in my .htaccess file
Options +FollowSymLinks
RewriteEngine on
RewriteRule services services.html?
http://www.domain.com/services.html to get rewrite url
http://www.domain.com/services
Please guide me for this
I think its supposed to be
RewriteRule ^services$ services.html [L]
or
RewriteCond /%{REQUEST_FILENAME}.html -f
RewriteRule ^([a-zA-Z0-9_-\s]+)/$ /$1.html

rewrite url module in windows does not redirect

I have used rewrite url module but I am not able to redirect to the target page and
I am getting error as:
The requested URL /old.html was not found on this server.
Here is my code:
<IfModule mod_rewrite>
RewriteEngine On
RewriteRule ^old.html$ new.html [R]
</IfModule>
Is AllowOverride set to All in your httpd.conf? Like this:
AllowOverride All
Also, your .htaccess should inlcude the L modifier for the last rule, and if you really want to redirect permanently, R=301:
RewriteEngine On
RewriteRule ^old.html$ /new.html [R=301,L]
You need to escape the . in .html with a \
So its:
RewriteEngine on
RewriteRule ^old\.html$ new.html [R]
Try also setting the RewriteBase to / like so
RewriteBase /
I've also tried this code for
RewriteEngine On
RewriteBase /
RewriteRule ^old.html$ /new.html [R=301,L]
error as The requested URL /old.html was not found on this server.
How to check the load module in apache server?

Resources