Problem with .htaccess a very peculiar case - .htaccess

I am using .htaccess and mod_rewrite to make URLs in my application more user friendly.
I have a page myapp.com/register.php and I use the below in .htaccess to make it work like myapp.com/register:
RewriteEngine on
Options +FollowSymLinks
RewriteBase /
RewriteRule ^register/$ register.php
It doesn't work, but when I change the code like:
RewriteEngine on
Options +FollowSymLinks
RewriteBase /
RewriteRule ^aregister/$ register.php
Then access the url myapp.com/register the page gets loaded fine.
Is this a peculiar case? Or am I doing it wrong? Please suggest.

Related

Rewrite rules .htaccess file of Drupal

I have installed a Drupal site in www.example.com/beta
I am trying to do the following
Redirecting users to /beta when they hit www.example.com which I have achieved
RewriteBase /beta
Modify the URLs. For example www.example.com/beta/products should be modified to www.example.com/products. I just need to remove the /beta from the url.
You can do it by this code:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteRule ^beta/(.*)$ /$1 [L,NC,R]
Regards.

.htaccess redirect a dynamic page to an external page URL won't work

I need to redirect a few specific dynamic php pages to an external website domain. For example,
siteA.com/home/space.php?uid=357&do=thread&id=396
to
siteB.com
I put the following in my .htaccess but it didn't work.
Options +FollowSymlinks -MultiViews
RewriteEngine On
Redirect home/space.php?uid=357&do=thread&id=396 http://www.siteB.com
what's wrong with this? any suggestion is appreciated. thanks!
From this:
Redirect home/space.php?uid=357&do=thread&id=396 http://www.siteB.com
to this:
RewriteRule ^[home/space.php?uid=357&do=thread&id=396]+$ http://www.siteB.com [R=301,L]
You need to use RewriteCond for matching query string:
Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteCond %{QUERY_STRING} ^uid=357&do=thread&id=396$ [NC]
RewriteRule ^home/space\.php$ http://www.siteB.com [L,NC,R=302]

URL Rewriting on Apache Linux

Thanks in advance !! Actually i am suffring from url rewriting problem in php (apache server). Problem is :
I have to write
URL(Old)= abc.com/search_result.php?id=110 to
URL(New)= abc.com/110
it is working in opposite direction when i click the url abc.com/search_result.php?id=110 it does not change to abc.com/110
but when i click the url abc.com/110 it changes to abc.com/search_result.php?id=110
.htaccess code
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^([a-zA-Z0-9]+)$ http://www.abc.com/search_result.php?id=$1
website linnk : [ncrfloors.com][1]
Please anybody help me.....
On your old domain: 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 /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+search_result\.php\?id=([^\s]+) [NC]
RewriteRule ^ http://abc.com/%1? [R=301,L]

How to change specific page slug with .HTACCESS?

I got a website script where it's very difficult to change page slugs.
So I thought I can do this with .htaccess.
I got my page url like - www.mysite.com/submit
So can I change this with .htaccess to www.mysite.com/create ???
Thank you!
Something as simple as your example can be easily done by .htaccess. Use this code in .htaccess under DOCUMENT_ROOT:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^submit/?$ create [L,NC,R]
RewriteRule ^create\$ /submit [L]
or
RewriteRule ^create$ /submit [L]

htaccess rewrite doesn't work properly on localhost

I'm restructuring a site now, and I'm testing it on localhost (xampp).
In the root directory there were a couple of .htm files, which were converted to .php.
However I'd like to keep the .htm extension for SEO reasons.
So I created a .htaccess file with this content:
Options +FollowSymlinks
RewriteEngine On
RewriteRule ^(.*)\.php$ $1.htm [L]
But when I try to access a page like this to test rewrite:
http://localhost/sitename/anything.php
I always get to
http://localhost/C:/xampp/htdocs/sitename/anything.htm
which obviously produces a 403 error.
I have tried to change .htaccess options, but no success.
Rewrite module is enabled in Apache, so it is not the case.
Am I missing something?
Try adding a RewriteBase directive i.e.
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteRule ^(.*)\.php$ $1.htm [L]
Try to redirect using the requested URI:
RewriteEngine On
RewriteRule ^(.*)\.php$ %{REQUEST_URI}.htm [R=301,L]
I tested it and it added ".htm" to all my php URIs test.php -> test.php.htm
No need for backreferences here.

Resources