htaccess mod_rewrite problems, what's wrong with my file? - .htaccess

What's wrong with my .htaccess file?
RewriteEngine on
RewriteRule ^/([a-zA-Z]+)/([0-9]+)$ index.php?mode=$1&id=$2 [L]
Basically I want it to go from example.com/?mode=page&id=1 to example.com/page/1
From what I see,it's supposed to work but it doesn't...

Remove leading / from your rule
Add RewriteBase / after RewriteEngine line

Related

mod_rewrite substitution not working

I'm having trouble with an Apache mod_rewrite. My .htaccess file is located in "/posts". Here's the contents:
RewriteEngine on
RewriteBase /
RewriteRule ^.*\.html$ ?url=/posts/2014/1215A.html [QSA]
The incoming request is for "/posts/2014/1214A.html". I want that request to be rewritten so as to be for, "/?url=/posts/2014/1215A.html". It appears that the regular expression is matched. The problem seems to be with the substitution. I've actually had the whole thing working; but, I must have somehow messed something up. Can anyone please tell me how to fix this? Thanks.
... doug
This should work :
RewriteEngine on
RewriteBase /posts/
RewriteCond %{REQUEST_URI} !^/posts/index
RewriteRule ^.*\.html$ ?url=/posts/2014/1215A.html [QSA]

Using .htaccess and mod_rewrite

I'm having some mod_rewrite problems with my .htaccess..
RewriteBase /folder
RewriteEngine on
Rewrit­eRule ^(.*)$ basic.p­hp?­url=$1 [L]
Above is what I'm currently using. However, I have no idea what I'm doing to be honest as I'm just cycling through the internet trying to figure this out.
Basically, for my website, if you type in
www.domain.com/folder/xxx/
I want it to basically be www.domain.com/folder/basic.php?url=xxx.
For some reason, all that does is cause a 404 error :/
So can someone please politely point me in the right direction?
Ok, I will explain using your htaccess.
RewriteEngine on
Turn on the Rewrite Module to enable URL rewriting
RewriteBase /folder
Rewrite the Base Directory to directory name folder
RewriteRule ^folder/(.*)$ basic.php?url=$1 [L]
Remap every request make using the folder/***** to basic.php?url=********
Note: RewriteEngine On Should be the first statement on your case
RewriteEngine on
RewriteBase /
RewriteRule ^folder/(.*)$ folder/basic.php?url=$1 [L]
This is more of a problem with regexs than .htaccess files.
http://httpd.apache.org/docs/current/mod/mod_rewrite.html
http://www.regular-expressions.info/

ht access mod_rewrite query string append flag

I'm using these two lines in my htaccess to direct /something to /page.php?page=something. I'd like /something?key=value to translate to /page.php?page=something&key=value.
These lines do not seem to be working.
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^([a-zA-Z0-9]+)/$ /$1 [R,QSA]
RewriteRule ^([a-zA-Z0-9]+)$ /page.php?page=$1 [L,QSA]
Any ideas on how to improve this?
I've fixed the problem. It actually wasn't working because of another rule in the htaccess file which wasn't written correctly. The code above works fine. Thanks.

RewriteRule Pattern Problem after RewriteBase called

I want my js-files in the folder scripts to be redirected to a php which handels the caching. So the .htaccess looks like this:
Options +FollowSymLinks
RewriteEngine on
RewriteBase /eval/widget/scripts
RewriteRule ^(.*)\.js$ func.php?src=$1
The filename (without extension) should be passed to the php-file, but instead the src parameter is 'scripts/JAVASCRIPT_FILENAME'. What's wrong with this? Seems like RewriteBase doesn't set it correctly...
Change your rewrite rule to
RewriteRule ^.*?/(.*)\.js$ func.php?src=$1
You understanding of RewriteBase is incorrect.

URL rewrite using mod_rewrite in .htaccess

I am trying to rewrite the URL using the mod_rewrite apache module.
I am trying to use it as below :
Options +FollowSymlinks
RewriteEngine on
RewriteBase /
RewriteRule ^wants/testing.htm wants.php?wantid=$1 [L]
I have created a .htaccess file in the directory from where the files are accessed.
The mod_rewrite is also enabled.
With all these done, i still haven't been able to get it working.
Can someone please help me with this? Please let me know if i am missing something
Thanks in Advance,
Gnanesh
As per OP's comment:
The URL shows
mydomain.com/wants.php?wantid=123. I
need to make it look like
mydomain.com/wants/123
This should work for your case:
RewriteEngine on
RewriteBase /
RewriteRule ^wants/([0-9]+)$ /wants.php?wantid=$1 [L]
It will allow you to use http://yoursite.com/wants/123 and will silently rewrite it to wants.php?wantid=123
I think a leading slash (or rather the lack thereof) might be yoru problem:
Options +FollowSymlinks
RewriteEngine on
RewriteBase /
RewriteRule ^wants/testing.htm /wants.php?wantid=$1 [L]
Otherwise Apache might be looking for the PHP file in /wants/wants.php as it'll be treating it as a relative URL.
Hmm, so I gave it some thought and I guess you could do something like this ( only changed the regexp according to your comment, if I understood correctly ):
Options +FollowSymlinks
RewriteEngine on
RewriteBase /
RewriteRule ^wants/\d+$ /wants.php?wantid=$1 [L]
But I guess you could also leave out the $1 reference, and still be able to access the id in your wants.php. So
RewriteRule ^wants/\d+$ /wants.php [L]
should work too, and you can then use something like
<?php
$request = split('/', $_SERVER["REQUEST_URI"])[1];
?>
in your wants.php where the last element of the array would be your id ( or anything else you ever decide to rewrite and send to the script ).
If you want to use the rule in the .htaccess file in your wants directory, you have to strip the contextual wants/ from the start of the pattern. So just:
RewriteEngine on
RewriteRule ^([0-9]+)$ /wants.php?wantid=$1 [L]
Otherwise, if you want to use the rule in the .htaccess file in your root directory:
RewriteEngine on
RewriteRule ^wants/([0-9]+)$ wants.php?wantid=$1 [L]

Resources