.htaccess is not working under xampp and Ubuntu - .htaccess

I am trying to do a url rewrite with .htaccess that is not working. I have xampp installed on a Ubuntu Linux machine. Here is my .htaccess file:
Options +FollowSymLinks
#From: host/1/products/productname/30/
#To: host/1/index.php?product=productname&price=30
RewriteEngine On
RewriteRule ^1/products/([a-zA-Z]+)/([0-9]+)/$ 1/index.php?product=$1&price=$2
The comment lines in the code show what I am trying to do. I know that .htaccess is being read because if I uncomment the "From" line above, it throws a 500 server error. Otherwise, I get a 404 Object not found error. I have set AllowOverride All in httpd.conf and restarted apache. The error_log is not reporting an error.
Any ideas?
This is my .htaccess as of Dec 2 at 2:05 PM
Options +FollowSymLinks
#From: host/1/products/productname/30/
#To: host/1/index.php?product=productname&price=30
RewriteEngine On
RewriteRule ^1/products/([a-zA-Z]+)/([0-9]+)/$ 1/index.php?product=$1&price=$2
RewriteRule ^foo$ /bar`

Use this rule in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteRule ^1/products/([^/]+)/([^/]+)/?$ /1/index.php?product=$1&price=$2 [L,QSA,NC]
For css/js/images: Use absolute path in your css, js, images files rather than a relative one. Which means you have to make sure path of these files start either with http:// or a slash /.
Alternatively You can try adding this in your page's header:
<base href="/" />
to resolve all the relative resource links.

Related

.htaccess second RewriteRule note working

I have a PHP page like example.com/new/info.php?title=example. The .htaccess is in folder /new/. I tried it in the main directory also. My .htaccess looks like this:
ErrorDocument 404 /404.php
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)$ page.php?title=$1 [QSA,L,NC]
RewriteRule ^info/([a-zA-Z0-9_-]+)/$ info.php?title=$1 [QSA,L,NC]
The first Rule is working, but the second sends no GET['title'] to the server. The site info.php loads but without the variable. I have tested it on my localhost and it's working. I load it on my webspace and the second rule is not working.
I tried it also without new directory example.com/info.php?title=example and same not work.
What is my mistake?
It sounds like you have MultiViews enabled (possibly in the server config). You need to disable MultiViews for this to work. Add the following at the top of your .htaccess file:
Options -MultiViews
With MultiViews enabled, mod_negotiation will issue an internal subrequest for info.php when making a request for /info/example/ - before your mod_rewrite rule is processed, so no parameters are passed.

Redirect from a directory to a subdirectory

I have a webserver with an the followinf structure :
www
---diceroller
------web
I would like to redirect any request incoming to /diceroller to /diceroller/web, so the users don't have to type the /web in URL.
At the root of my server is a .htaccess containing the following elements :
Options -Indexes
ErrorDocument 404 /permalien.php
AddType text/cache-manifest .appcache
I tried to use the following .htaccess placed in the diceroller forlder, but I hit a 403 :
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^diceroller/(.*)$ /diceroller/web/$1 [R=301,NC,L]
Could someone help me to figure this out ?
RewriteRule's pattern is relative to your current directory. So if your htaccess is located in /diceroller , you have to remove that from the pattern, try the following instead
RewriteRule ^((?!web).*)$ /diceroller/web/$1 [L,R]

.htaccess Rewrite rules not firing

I am trying to come up with a rewrite rule that will rewrite:
oldurl.com/v11/file.ext to newurl.com/v11/file.ext
On the oldurl server I have put the following in .htaccess inside of the folder v11:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^v11/(.*)$ http://newurl.com/v11/$1 [R=301,L]
But the redirect is not firing at all. What did I do wrong?
When placing .htaccess in the v11 folder, your code should be:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^(.*)$ http://newurl.com/v11/$1 [R=301,L]
Check that the new server is set up to allow .htaccess files to be read at the directory level.
If the .htaccess file worked on the other server, it is most likely a server configuration issue or file owner/permissions problem.

.htaccess works locally, but gives 404 on GoDaddy

I have this code in my .htaccess file:
Options +FollowSymLinks -MultiViews -Indexes
RewriteEngine On
RewriteRule ^(design|JS|css|images|remoteLibraries|remoteLibraries/xAJAX/xajax_js/)($|/) - [L]
RewriteRule ^([a-zA-Z_]+)$ index.php?action=$1
RewriteRule ^([a-zA-Z_]+)/([a-z_A-Z]+)$ index.php?action=$1&tip=$2
It works fine on my local Apache server, but when uploading it to GoDaddy all I get is 404 Not found error ...
Any idea?
1) I recommend that you set a RewriteBase, usually just
RewriteBase /
which helps standardize where the rewrite takes effect, since the directory structure may be different between the local and remote servers.
2) I also recommend that whenever unexpected rewrite behavior crops up it is important to set
ErrorDocument 404 default
so that the Go Daddy 404 page is not redirected as well.

.htaccess rewrite resulting in 404 error

I am trying to create search engine friendly URLs with the following .htaccess and it is directing to a 404 error page no matter what I try.
This is on a Host Gator shared account, if it makes any difference. The directory is (document root)/blog, the .htaccess file is located in the directory "blog."
Example URL would be http://examplesite.com/blog/category/announcements.Here is the .htaccess file contents:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^category/([a-zA-Z0-9]+)/$ index.php?category=$1
Any ideas why this is happening?
RewriteRule ^category/([a-zA-Z0-9]+)/*$ index.php?category=$1 [R=301,L]
Forget the preceeding slash?
RewriteRule ^category/([a-zA-Z0-9]+)/$ /index.php?category=$1

Resources