I want to encode my website url(Url Masking).
For example if my original url is
http://domain-name/sample/example/test.php
I want it display url as
http://domain-name/test
how can i mask website address?
In general HTACCESS does not change the URL or mask the URL. You will have to rewrite the URL to the pattern you like and add instruction in HTACCESS to make the URLs patterns understandable by server
For more details about how to work with rewriting URL and HTACCESS check this website
Rewriting the URL otherwise named as Friendly URL
I assume in your code (HTML or PHP) you probably will have
link
which should be changed to
link
as part of rewriting the URL where http://domain-name/test URL is like alias
Now you should write instruction in .htaccess file to redirect the URL alias to actual URL
RewriteEngine On # Turn on the rewriting engine
RewriteRule ^test$ /sample/example/test.php [L] # Handle requests for "test"
Related
I am trying to mask the following url with any page number using htaccess.
https://sampledomain.com/?page=2
to
https://sampledomain.com/page/2
So if we call https://sampledomain.com/page/2 url in the website, internally path should always be calling https://sampledomain.com/?page=2 url
Please suggest me the correct htaccess rule.
In htaccess in your document root, use the following rule :
RewriteEngine on
RewriteRule ^page/([0-9]+)/?$ /?page=$1 [QSA,L]
I want to change a url like:
dynamicdomain.com/mypage
to
dynamicdomain.com/mydashboard
I want to display the content of mypage but the url that the users will see on the browser will contain mydashboard. How do I do this using .htaccess.
I tried using this:
RewriteEngine On
Redirect 301 /mydashboard /mypage
but this redirects the url:
dynamicdomain.com/mydashboard
to
dynamicdomain.com/mypage
Edit:
Here is another example on what I want to achieve:
I have a folder mypage which can be accessed as:
http://dynamicdomain.com/mypage/
I want the users to see http://dynamicdomain.com/mydashboard/
(mydashboard folder doesn't exists) when they access http://dynamicdomain.com/mypage/
can someone point me in the right direction.
Thanks.
Try these directives:
RewriteEngine On
RewriteRule ^mypage$ /dashbord [NC,L]
Redirect directive does an external redirect (redirects a URL to another URL). To redirect "dashboard" internally to "/mypage", you need to use the RewriteRule directive of the Rewrite module.
Put this in your htaccess file :
just after IfModule closes
Redirect 301 /mypage http://www.dynamicdomain.com/mydashboard
This will work for you.
thanks
i have to redirect one url to another. http://www.abc.com/realestate/ to Redirect to http://www.abc.com/businessfinder/company/4105/Property_Agent/. is it better to change on the codeigniter routes.php or the .htaccess file?
If you know that a URL should be redirected then there is no reason to hand the request to PHP. So, redirecting using the .htaccess file would be preferable.
If you have mod_alias installed then you can use the Redirect directive:
Redirect 301 /realestate/ http://www.abc.com/businessfinder/company/4105/Property_Agent/
You can also use mod_rewrite to jump between places in various ways. E.g.:
RewriteRule ^/realestate/?$ /businessfinder/company/4105/Property_Agent/ [R=301,L]
If that is not possible then you can use CodeIgniter's $this->url->redirect() method. It will send the user to any website you like.
I have a problem with creation a redirect 301 through htaccess for pages with parameters.
I want to redirect all pages in one directory to the homepage of another (the new URLs are without parameters and have a different structure so I just want to redirect to the main section)
It means - I have now
http://www.mysite.com/old_directory/page.php?s=12345
etc... and all of them I want to redirect to
http://www.mysite.com/new_directory/
How should I modify this redirect? Its Apache server and Wordpress platform.
If you end the substitution string with just a question mark, it will erase an existing query string. mod_rewrite
RewriteRule ^/old_directory/.* /new_directory/? [R=301,L]
Hi can anyone of you suggest me on how to redirect my page http://testsite.com/about.php to http://testsite.com/about/ by using htaccess rewrite rules.Without using any query string in the page url i need to rewrite it
I don't think you want a redirect but a rewrite. A redirect means informing the client to requery for the redirected url, whereas rewriting means telling the server to interpret an url as being some other url.
and you dont' want to rewrite about.php to /about/ but the other way around. You want your users to type in /about/ and that url to be handled by /about.php
and this is done by:
RewriteEngine on # this line enables rewrite
RewriteRule /about/$ /about.php
RewriteRule /about$ /about.php
I'm not sure if both of the above are actually needed or just one (I don't have access to an apache right now to test)
In the slight chance that you actually do want a redirect as you wrote, use this free redirect generator: http://www.htaccessredirect.net/ (it's easier than learning all the quirks of the conditions to match up)
in your case that will be:
Redirect 301 /about.php /about/