mod_rewrite issue with GET parameter - php

I'm modifying the Apache .htaccess file for rewrite products' URL, so I can go from this
domain.com/section/products/product.php?url=some-product-name
to this
domain.com/section/products/some-product-name
Here's the mod_rewrite code that I'm using:
Options -Indexes
Options +FollowSymlinks
Options -MultiViews
RewriteEngine on
RewriteBase /
RewriteRule ^section/products/(.*)$ /section/products/product.php?url=$1 [QSA,L]
It just returns a 500 server error.
What could be the issue?

It is because your rewrite rules are infinitely looping. Which is due to the fact section/products/(.*) pattern matches original and rewritten URI.
You can use this to fix it:
Options +FollowSymlinks -Indexes -MultiViews
Options -MultiViews
RewriteEngine on
RewriteBase /
RewriteRule ^(section/products)/([\w-]+)$ $1/product.php?url=$2 [QSA,L,NC]

Related

Rewrite query string with htaccess

I need to rewrite this url
category.php?cat=computers
to
category/computers
Or, is it the other way round?
How do I do that with .htaccess?
The rule is:
RewriteRule ^category/(.+)/?$ category.php?cat=$1 [NC,L]
your .htaccess should look like this:
<IfModule mod_rewrite.c>
#if the name of the php file is the same of the path, you have to remove MultiViews
Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteRule ^category/(.+)/?$ category.php?cat=$1 [NC,L]
</IfModule>

How to modify this URL in .htaccess?

I want to modify URL with a check.
If there exists experiment as second folder, then do this
{site}.com/dashboard/experiment/closed/.../
to
{site}.com/experiment/closed/.../
If no experiment found in path, then don't do anything. For eg
{site}.com/dashboard/ex-view/closed/.../
How do I achive this using htaccess. I'm using Laravel 5.1.
This is what I tried but it doesn't meet the second condition.
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^experiment/(.*)$ /$1 [L,NC,R]
You can try this rule in the .htaccess in the root. The should only affect URL with experiment as the second folder.
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^.+/experiment/(.*)$ /experiment/$1 [L,NC,R]

Simple RewriteRule do not work at php/apache in htaccess

I do not know why, but this simple Rule will not work.
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteBase /
RewriteRule ^rubbellos\.png/$ rubbellos/rubbelbild_png.php [NC,L]
RewriteRule ^rubbellos\.css/$ rubbellos/rubbellos_css.php [NC,L]
</IfModule>
If I copy the xyz/rubbellos/rubbelbild_png.php to browser it is OK.
My approach is to bring the request of rubbellos.png to the .php-file. But I get a file not found.
Thx for any hint in advance.
You have 2 errors:
use a RewriteBase since you're talking about a subdirectory /xyz/ in your question.
disable MultiViews option to avoid unexpected behaviour with rubbellos (virtual file and existing directory).
You can replace your current code by this one in your htaccess (which has to be in /xyz/ folder)
Options -MultiViews
RewriteEngine On
RewriteBase /xyz/
RewriteRule ^rubbellos\.png$ rubbellos/rubbelbild_png.php [L]
RewriteRule ^rubbellos\.css$ rubbellos/rubbellos_css.php [L]
Note: don't forget to replace xyz by your real subdirectory's name

Using .htaccess to redirect to relative address

I am very new to URL rewriting using .htaccess and I would like to redirect anyone entering the domain below
http://domain.tld/admin
to be redirected to
http://domain.tld/index.php?section=admin
but without including the full address. This is the code I am using but it doesnt seem to work
Options -Indexes
Options +FollowSymLinks
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^admin /index.php?section=admin
</IfModule>
Where Im I going wrong?
Thanks
You can use this more correct regex rule with L flag:
Options +FollowSymLinks -Indexes
RewriteEngine On
RewriteBase /
RewriteRule ^admin/? index.php?section=admin [L,QSA,NC]

Friendly URLS / URL Rewriting using .htaccess on godaddy shared server

I have been looking all over the place to find some code to work with my godaddy URL Rewriting, but no luck.
I am trying to make my website with Friendly URLS with .htaccess e.g. domain.com/company/buy/items.php?fatherID=23 ==> into ==> domain.com/23 I tried almost all codes and the best i got to is removing the .php
Sample Code:
Options +FollowSymLinks -MultiViews
Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^/([0-9]+)/?$ company/items.php?fatherID=$1 [NC,L]
Does anyone have any idea with some simple code? I am on godaddys shared Linux server.
I tried to redurect 404 error codes with:
ErrorDocument 404 /domain.com/home/404error.php
but this also did not work.
Is there something I am missing?
Try this , it should be work
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine on
RewriteBase /
RewriteRule ^([0-9]+)$ company/items.php?fatherID=$1 [L]
</IfModule>
Godaddy is a special case. It will work surely.
DirectoryIndex index.php
AddDefaultCharset utf-8
RewriteEngine on
Options +FollowSymlinks -MultiViews -Indexes
RewriteBase /
RewriteRule ^/([0-9]+)/?$ company/items.php?fatherID=$1 [NC,L]

Categories