Rewrite friendly URL not work by click on link - apache

I'm trying to rewrite my website URL to more friendly URL, for example:
www.mysite.com/profile.php
to
www.mysite.com/profile
so far I'm able to do it by writing the rewrite URL in the URL address bar, but when go to the page by click on the link, the profile page URL doesn't change to rewrite URL. Am I missing something here?
this is my .htaccess codes
Options +FollowSymLinks
RewriteEngine On # Turn on the rewriting engine
RewriteRule ^profile/?$ profile.php [NC,L] # Handle requests for "profile"
Thanks for any suggestions.

You need to change the URL of profile..
Profile

mod_rewrite will not change URLs in your code. You have to do it.
If you can't or don't want to, you can use RewriteRule with R option to map from old to new URL.

It doesn't change because your rule only internally rewrites profile to profile.php, you need a different rule to do it the other way, and externally so the browser gets redirected:
RewriteCond %{THE_REQUEST} \ /profile\.php
RewriteRule ^ /profile [L,R]

Related

Redirect with .htaccess but getting old URL as parameter

I want to create a .htaccess file which redirects me from
https://example.net/#UserName to https://example.net/user/index.php?user=UserName, but only when there is the #.
Can someone please help me?
You can use this in your htaccess file:
RewriteEngine On
RewriteRule ^#([^/]+)/?$ https://example.net/user/index.php?user=$1 [L,R]
This will redirect a URL of the form example.com/#foobar to https://example.net/user/index.php?user=foobar changing the URL in browser address bar. However, if you do not want the URL to change, use the following instead
RewriteEngine On
RewriteRule ^#([^/]+)/?$ /user/index.php?user=$1 [L]

How to redirect URL Friendly created with rewrite

I created URL with rewrite mod.
This is the command:
RewriteRule ^productos/(.+)-(.+).html ecommerce/buscador.php?categoria=$2
Example the URL
http://www.frutasadomicilio.cl/productos/Verduras-2.html
The URL works good but now i need change the URL. I am thinking that with redirect 301 is my way an a solution. But when i try the redirect the URL, the command return the new url but with parameter.
The command is:
redirect 301 /productos/Verduras-2.html /productos/Verduras_a_domicilio-2.html
when I access the URL from google search, the Browser return this URL with parameter
http://www.frutasadomicilio.cl/productos/Verduras_a_domicilio-2.html?categoria=2
Any suggestion?
Thanks
Do not mix Redirect and RewriteRule for similar URLs. I suggest you to use only RewriteRule as
RewriteEngine on
RewriteRule ^productos/Verduras-2\.html$ /productos/Verduras_a_domicilio-2.html [R=301,L]
RewriteRule ^productos/(.+)-(.+)\.html$ ecommerce/buscador.php?categoria=$2 [NC,L]
Also, the order of the rules above is important.

Redirecting complex URL Aliases in htaccess

I need to redirect sample.com/newdomain/calendar to an external link however I already have a rewrite rule in place to redirect sample.com/newdomain/ to newdomain.sample.com/ so when I enter sample.com/newdomain/calendar into the web browser it takes me to newdomain.sample.com/calendar. How can I override the original rewrite I have written to allow sample.com/newdomain/calendar to redirect to an external url.
The rewrite rule that will redirect any url containing /newdomain is:
# Redirect /newdomain to newdomain.sample.com
RewriteRule ^newdomain(/.*)?$ http://newdomain.sample.com$1 [R=301,QSA,L]
Any help is appreciated!
You can place new redirect rule above the previous rule and make sure to clear your browser cache before testing:
RewriteEngine On
RewriteRule ^newdomain/calendar/?$ http://external.site.com/ [R=301,NC,L]
RewriteRule ^newdomain(/.*)?$ http://newdomain.sample.com$1 [R=301,NC,NE,L]

.htaccess redirect doesn't hide url

my .htaccess in the root folder includes the following lines :
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^(.*)\.htm$ http://example.com/?city=$1 [NC]
when I open the address http://example.com/bla.htm, my browser doesn't hide the GET values specified in the .htaccess, it redirects me to ?city=bla. eventhough I'm not using the [R] switch. This has always worked for me before (as I remember, haven't dealt with htaccess in a while). What's wrong here ?
When you redirect to an entire URL, it doesn't do URL rewriting (you can't exactly rewrite URLs on someone else's website).
Assuming both URLs are on the same server, you need to do something like
RewriteRule ^(.*)\.htm$ index.php?city=$1 [NC]
Also, I'd recommend getting into the habit of using the [L] switch whenever you can - it helps avoid bugs when you have a lot of URLs to rewrite.

how do I redirect a user to a certain page using .htaccess

I have the following rule defined in the .htaccess file of my webapplication's root directory.
RewriteCond %{REQUEST_URI} !^/classes/captcha.php
RewriteRule ^([^/]*)/([^/]*)$ /index.php?client=$1&page=$2 [L]
this rule give the facility of typing the url like this xyz.com/abc/page1 which is in original is equal to xyz.com/index.php?client=abc&page=page1
Now what I want is that when a user types in http://xyz.com/abc/page1, the address bar of the browser should display the original url i.e. 'http://xyz.com/index.php?client=abc&page=page1'
currently if I type "http://xyz.com/abc/page1" the address bar url doesn't change.
Please help me modify this rule.
Thanks.
Try adding the redirect flag:
RewriteRule ^([^/]*)/([^/]*)$ /index.php?client=$1&page=$2 [R=301, L]