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

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]

Related

mod_rewrite issue with GET parameter

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]

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]

not rewriting .asp files using htaccess

I have .asp files re-writing themselves to .php files using htaccess and a rewrite rule on another site. it works fine but I am trying to do the same on my other site with one URL and it doesn't work. both have mod_rewrite enabled and on similar servers. (Apache v3.22.17 rev9999 / PHP v5.4.21)
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.+).(asp)$ $1.php [L]
</IfModule>
this is the full htaccess code.. can you see anything wrong with this?
I'm not really good with mod_rewrite however have you tried this:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^(.+).(asp)$ $1.php [L]

Categories