.htaccess modrewrite not redirecting my links - php

I'm changing my website links to a SEO friendly urls, I did every thing in php file and changed the urls as following:
http://mywebsiet.com/news-details.php?id=2012/6/21/newstitle.html
how can I redirect to:
http://mywebsiet.com/2012/6/21/newstitle.html
I tried this Generating tool from www.generateit.net/mod-rewrite/
and created the .htaccess with the code provided:
RewriteEngine On
RewriteRule ^([^_]*)$ /news-details.php?id=$1 [L]
and even so, nothing get changed.... any ideas?

Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^(.+?\.html)$ /news-details.php?id=$1 [L,QSA,NC]

Related

.htaccess rule for language detection in subdirectory

I have an URL that is https://www.myurl.com/subdir/language/login.php .
The "language" parameter is not an existing subfolder. The folder structure is:
root/subdir/.htaccess
As you can see the .htaccess file is located in https://www.myurl.com/subdir/.htaccess
I would like to do a .htaccess Rewrite Rule in order to change the called uri:
https://www.myurl.com/subdir/en/login (without .php)
to:
https://www.myurl.com/subdir/login.php?lng=en
My current apporach is:
# MultiViews must be disabled for the rewrite to work
Options -MultiViews
# Turn on the rewriting engine
RewriteEngine On
RewriteBase /subdir/
RewriteRule (en|de)(/login)$ login.php?lng=$1 [L]
But when I call the URI https://www.myurl.com/subdir/en/login I get an http error code 404.
Yes thats it! One more question, what if the scenario is all the same, but I would like to get the (en/de) in front of /subdir/ ? So the url would be myurl.com/en/subdir/login:
In this case rule must be placed in site root .htaccess instead of subdir/.htaccess with this rule:
Options -MultiViews
RewriteEngine On
RewriteRule ^(en|de)/(subdir/login)/?$ $2.php?lng=$1 [L,QSA,NC]

mod re write help - WAMP

Looking to re write a url in WAMP. I have AllowOverride Al (conf file). The mod rewrite modules is loaded. I am working on localhost
What i want to acheive is that on login the user gets redirected
localhost/propcms/xxxxxxx/
the actual address is
localhost/propcms/status.php?id=xxxxxxx
the .htaccess file has the following (and is located in localhost/propcms/ )
Options +FollowSymlinks
RewriteEngine on
RewriteBase /propcms/
RewriteRule ^propcms/([^/]*)/$ /propcms/status.php?id=$1 [L]
this is what i get....The requested URL /propcms/test121/ was not found on this server.
any ideas ??
Since you are specifying a rewritebase, you should not include it in your rewrite rule:
Try this snippet :
Options +FollowSymlinks
RewriteEngine on
RewriteBase /propcms/
RewriteRule ^([^/]*)/$ /propcms/status.php?id=$1 [L]

htaccess and mod_rewrite redirect error

on ubuntu 13.04 and apache2 and php 5.4 i got the 404 error.
mod rewrite is enabled on my machine
my .htaccess code is like this:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^/dl/([0-9]+)/$ dl.php?id=$1
</IfModule>
and the dl.php is set up for just echo the variables:
<?php
print_r($_GET);
?>
on output when i will go to this address http://localhost/digidoc/dl/5 it shows the 404 error
p.s.:the .htaccess file included in digidoc folder and digidoc folder is in web server root
Change
RewriteRule ^/dl/([0-9]+)/$ dl.php?id=$1
Into
RewriteRule ^/digidoc/dl/([0-9]+)/?$ dl.php?id=$1
Notice the ?, so the last slash is optional. Also add digidoc/ as the rule is applied to the whole url.
You need to get rid of the leading slash:
Options -Multiviews
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /digidoc/
RewriteRule ^dl/([0-9]+)$ dl.php?id=$1 [L,QSA]
</IfModule>
You should also include a rewrite base as well as making sure that you have multiviews turned off.

Subfolders Url rewriting using htaccess

i am working within sub folder of my website and i want to rewrite my urls.
i have never done this before nor have any knowledge of rewriting rules.
I have a file which named show.php which takes parameter id which is any no and then it echo that no on to the screen.
Now this file is in folder name polo.
www.xyz.com/polo/show.php
i want to rewrite
www.xyz.com/polo/show.php?id=10
to
www.xyz.com/polo/id/10
I tried this answer but still its not working.
Subfolders using htaccess
Any help would be appreciated.
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^(polo)/(id)/([0-9]+)/?$ /$1/show.php?$2=$3 [L,QSA,NC]

URL Rewriting-Page display - rewrite rule in .htaccess

For URL Rewriting, i have got the output for static URL
But , for dynamic URL , i am getting partial output only.
I have placed the .htaccess file in the root directory only.
Here is the code:
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^booking/price/([0-9]+)/?$ booking.php?price=$1
What will be the solution ?
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^booking/([0-9]+)/?$ booking.php?price=$1
RewriteRule ^booking/([0-9]+)/([0-9]+)/?$ booking.php?price=$1&pass=$2
You really want to customise your code for these though so as to be able to use general rules, rather than converting specific paths to use $_GET.
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^booking/([0-9]+)/?$ booking.php?price=$1
RewriteRule ^booking/([0-9]+)/([0-9]+)/?$ booking.php?price=$1&pass=$2
For images and Css you need to define your base folder in htaccess file as
RewriteBase /~your folder/

Categories