I used the following code in my htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
</IfModule>
It redirects as if the url is test.com/test --> it redirects to test folder (Here the folder is available in the name of 'test')
If the url is test.com/testpage --> it redircts to index.php (i.e no one folder is in the name of testpage)
But i want to redirect this as
if the url is test.com --> it will redircts to index.php
if the url is test.com/test --> It will redirects to corresponding folder (if the folder name exists)
if the url is test.com/testpage then it redirects to page.php
Also i want to redirect some particular name to test.php (test.com/test2 or test.com/test3)
Please help this
This is done by creating a router class.
The code you have there redirects all urls to index.php making index be able to read the url and base it's contect on that.
see http://www.phpaddiction.com/tags/axial/url-routing-with-php-part-one/
for router tutorial
you can individually write their rewrite conditions for specific pages/urls or just add some sort of suffix like along with page pass "[category]/testpage" or any thing and describe the rewrite condition so that it can be redirected.
RewriteRule ^category/(.*)$ page.php [R=301]
Related
Want to Redirect to index.php
When user try to come at site using any URL like:
1)www.domain.com/xyz
2)www.domain.com/abc
3)www.domain.com/apple
4)www.domain.com/123
5)www.domain.com/hello
Whatever random text at the end of the URL.
I want .htaccess code which redirects those URL to
www.domain.com/index.php
index.php contain code to get data using GET method so the last string of URL needs to get in index.php file.
RewriteEngine on
RewriteRule ^(.*)$ http://www.example.com/index.php?parameter=$1
I tried this code but it goes in infinite redirect.
I want to stop loop while parameter found.
You should be redirecting to a relative address (assuming that index.php is on the same domain). Also, you need to exclude existing files:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
I currently have a website with URLs with this pattern
https://website.com/?p=something
where p is the requested page (like /?p=login)
for SEO reasons i want the URL to look like this
https://website.com/login/
Of course I could do a redirect like this
Redirect 301 /login/ https://website.com/?p=login
But it would change the URL displayed in the users browser back to the URL with parameters in it.
My question is, how can I have an URL like this https://website.com/login/ but in PHP inside the index.php I could access the requestet page or "path" like before like $page = $_GET['p'];. In other words I want to redirect the URL https://website.com/login/ to https://website.com/?p=login but having the URL still displayed as https://website.com/login/.
I'd suggest to use .htaccess file to point all requests to the server to one file for example index.php
# Rewrite Engine ON
RewriteEngine on
# Redirect everything to one file
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L]
After that you can code a router to handle URI components.
For example someone call sitename/login
You detect /login and open the required page
I have a WordPress installation in my main folder, so my site goes like
www.example.com
Besides that I have a subfolder with a separate static site that you can access with
www.example.com/special
So in the special pages I have a page called
www.example.com/special/my-special-page
It's actually a .php file, but I've removed the extensions in the .htaccess file of that special site with this
RewriteEngine On # Turn on the rewriting engine
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
And this works.
But my client said: I want, when I enter
www.example.com/myawardspage
to go to
www.example.com/special/my-special-page
but to have the above URL (without /special/my-special-page) in it. So in the main .htaccess file (the one that controls the WordPress) I've added
RewriteRule ^myawardspage?$ http://www.example.com/special/my-special-page [NC,L]
So now when you go to
www.example.com/myawardspage
I am redirected to
www.example.com/special/my-special-page
which is great, but I need the URL to look like
www.example.com/myawardspage
So in the .htaccess file of the special page I've added
RewriteRule ^myawardspage/?$ /special/my-special-page [NC]
But the URL remains the same (http://www.example.com/special/my-special-page).
What am I doing wrong here?
Just below RewriteEngine on, place the following lines in your /.htaccess (document root) file:
# Check if the file being requested exists
# in the 'special' directory
RewriteCond %{DOCUMENT_ROOT}/special/$1.php -f
# If so, then rewrite accordingly:
RewriteRule ^([^.]+) special/$1.php [L]
Using this method means that you don't need that rule in the special/.htaccess file - you can safely remove it.
Ok, so you mean when ever you want to hit www.example.com/myawardspage then you want to get data from www.example.com/special/my-special-page while in your address bar your address remains www.example.com/myawardspage To achieve this apply this rule in your WordPress installation's .htaccess file.
RewriteRule ^myawardspage/?$ www.example.com/special/my-special-page [NC,L] # Handle requests for "www.example.com/special/my-special-page"
It wil get you desired data and your problem will be solved. Let me know if that works for you.
I have a webpage which was built with core php, now its been updated to codeigniter mvc. Problem which i am facing is, users are trying to enter the old URL path
example: www.website_name/old_path
now since the mvc layout, it wont work and will get 404 error. i want to redirect the clients who enters www.website_name/old_path for the new one
www.website_name/index.php/new_controller/new_view.
Anyone please help me to resolve this issue.
Thank You!
first of all remove index.php config file.
Open config.php and do following replaces
$config['index_page'] = "index.php"
to
$config['index_page'] = ""
Then create HTACCESS file in application/ folder
having this code....
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
Now index.php is removed from your URl....
STEP 2) open application/config/routes.php file
Now here define your desired web URL
$route['mycontroller/(:any)'] = "mycontroller/user_detail/$1";
So,Your URL Will be ..
www.website_name/new_controller(or xyz)/
Here you can also change the controller name differently using routes So no one can get the exact name of controller/method name....To Do such customization refer this URL
http://www.codeigniter.com/user_guide/general/urls.html
As Sumit mentioned, you should use URL Routing for this.
In the routes file you can create a list of all the redirects that you want like so:
$route['old_path'] = "new_controller/new_view";
You can use 301 redirect for this type of issue.
Put this code in .htaccess
RewriteRule ^www.website_name/old_path www.website_name/index.php/new_controller/new_view [L,R=301]
or use 301 redirect of codigniter http://www.codeigniter.com/user_guide/helpers/url_helper.html
// with 301 redirect
redirect('/article/13', 'location', 301);
My web application url is something like http://www.example.com
Now i want that the end user will always see http://www.example.com in there
browser inseted of something like http://www.example.com/index or any thing after the / will not show to the end user
i.e http://www.example.com/abc.php?id='someid'
will display in the user browser as http://www.example.com
Thank You in advance and sorry for the bad english.....
There are several ways to do that. REST web service, URL shortening, changing the alias or creating an .htacces file.
An easy way to do that would be creating an .htaccess file in your root directory.
If you’re running Apache, you can do that by creating a redirect in your site’s .htaccess file. If you don’t already have one, just create a new file called “.htaccess” in your site’s web root.
Save this inside your .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
# Send would-be 404 requests to Craft
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]
</IfModule>
That rewrite rule basically says, “If a request is coming in that doesn’t map to an existing folder or file, pass it along to index.php instead.”
source http://buildwithcraft.com/help/remove-index.php
and check this htaccess remove index.php from url