Forum Moderators: phranque
I used .htaccess file and write below code
RewriteEngine on
RewriteRule ^(.+)/$ index.php?$1 [L]
My problem is that,when somebody type http://example.com/search.php
here trailing slash("/")not added so this URL not redirect to the index.php page.
Please give me solution ,My project is going to release shortly
[edited by: engine at 11:45 am (utc) on July 2, 2008]
[edit reason] examplified [/edit]
My problem is that,when somebody type http://example.com/search.php
here trailing slash("/")not added so this URL not redirect to the index.php page.
Secondly, you really don't want to redirect to example.com/index.php - you should redirect to example.com/ instead, but not all different pages should be redirected to the homepage to avoid duplication errors and confusion.
Third, check the forum library for relevant threads, and especially see the one on writing regular expressions and on how to do a 301 redirect.
Added:
In addition, are there query strings after search.php - like search.php?id=widgets
[edited by: Marcia at 11:50 am (utc) on July 2, 2008]
Here i use URL rewriting in .htaccess file.I redirected every URL like
http://example.com/search.php/ to the index.php page.
Using example.com, not your real URL:
If every URL is like
http://example.com/search.php/
What do some of the other URLs look like, that are like that?
http://example.com/search.php/1
http://example.com/search.php/2
What comes after search.php on other pages?
If next URL is http://example.com/login.php/ ,I forward User to the index.php page and on that page i extract "login" from URL "http://example.com/search.php/" and include login.php page there means i consider action is "login" here.
I have done this because i want every URL should redirect to the index.php so i pick the action and include corresponding page.
In addition, There are no query strings after search.php - like search.php?id=widgets
RewriteEngine on
RewriteCond $1 !^index\.php$
RewriteRule ^(.+)[b]/?$[/b] index.php?$1 [L]
However, what Marcia is referring to is that the correct way to do this would be to redirect requests with an added slash to remove the slash. In this way, you would avoid creating duplicate content -- The same page appearing at more than a single unique URL -- and a sure way to cause search engine ranking problems:
RewriteEngine on
#
# If filetype is present in requested URL, externally redirect to remove trailing slash
RewriteRule ^(.+\.[^/]+)/$ http://www.example.com/$1 [R=301,L]
#
# Internally rewrite x.php to index.php, unless URL-path is already rewritten to index.php
RewriteCond $1 !^index\.php$
RewriteRule ^(.+\.php)$ index.php?$1 [L]
#
But in the administrator directory(Administrator of site is here)
I have used URL like below
http://example.com/administrator/index.php?action=emailKeywords
http://example.com/administrator/index.php?action=messages
Which is having query string:
query strings after index.php -- like index.php?action=emailKeywords
This URL:: http://example.com/administrator/ having my administrator login.
so when i write http://example.com/administrator/ instead of administrator login ,i m getting redirect to site index page.
You may need to add "exclusions" to the second rule to prevent rewriting any "special" directory URL-paths, such as your administrator subdirectory:
# Internally rewrite x.php to index.php, unless URL-path is already
# rewritten to index.php or /administrator subdirectory is requested
RewriteCond $1 !^index\.php$
RewriteCond $1 !^administrator/
RewriteRule ^(.+\.php)$ index.php?$1 [L]
#
For more information, see the threads in our Apache forum library, and the references cited in our forum charter. You will find the links at the top of every page in this forum.
Jim