I'm not familiar with servers and htaccess commands. I think I have a simple question.
I put a index.php file on the root of localhost. That file will generate the following the following pages on this links:
http://www.website.com/index.php?page=home
http://www.website.com/index.php?page=services
http://www.website.com/index.php?page=contact
Old path adress: http://www.website.com/index.php?page=home
New path adress: http://www.website.com/home
When user access the new path adress, I want the server to show what old path contains.
I want to use alias, no redirect.
Thank you for your time.
Make sure the links in your content all look like: http://www.website.com/home then add these rules to your htaccess file in your document root:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /index.php?page=$1 [L,QSA]
Related
I am trying to rewrite yii urls but with no luck. I have spent hours going through sites and come up with the same answer each time which doesn't work for me:
http://www.yiiframework.com/doc/guide/1.1/en/topics.url#user-friendly-urls
I would like to resolve the urls to basic paths e.g
/index.php/site/index
to
/
/index.php/ads and /index.php/ads/
to
/ads
/ads/details?ad=9
to
/ads/9
The problem seems to be that the .htaccess has no effect.
I am using:
mamp pro
on a mac with lion
and the web directory is different to the webserver root.
I have set AllowOveride through the console.
The .htaccess is in the same folder as the main index.php but doesn't register even if I create an error.
I have had no problem with other non-yii web directories using an htaccess file
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ /index.php
//main.php
'urlManager'=>array(
'urlFormat'=>'path',
'showScriptName'=>false,
'rules'=>array(
'<controller:\w+>/<id:\d+>'=>'<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
),
),
I have a project where my Yii application is in a subfolder as well.
This is my .htaccess file:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\?*$ index.php/$1 [L,QSA]
Then in main.php, you'll need to add these lines to the 'rules' array:
'' => 'site/index', // This is for the home page
Is ads the name of your controller? In other words, do you have a file named AdsController.php in your controllers folder? If so, then it will work by default.
Just curious why you're hitting the index.php directly? You should be able to setup your localhost to point directly to your Yii app folder. For example, on my machine I created http:// mytestapp/ and it points to the app's folder in htdocs.
Since you're on a Mac, you need to edit your etc/hosts file as well...
I added a line like this:
127.0.0.1 mytestapp
Hope that helps...
We have just copied a Codeigniter website (from our root domain) to a subdirectory on the same root domain (with all config.php changes made and a new database etc.). However, page links don't display the individual pages yet the browser simply reloads the index.php page content (as if it's loading a new page) and changes the URL in the browser window to the correct page.
This is really odd and I've spent hours pouring over it, so I'm hoping someone here may be able to give me a starting search point.
For your information, the .htaccess in the subdirectory is:
RewriteEngine on
RewriteRule ^test.php$ mod_rewrite.php
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
if theres a new codeigniter install in a subdirectory now that used to be on the root, you need to include the name of the sub directory in front of the index.php parts of your htaccess
something like this(the change is on the last line):
RewriteEngine on
RewriteRule ^$ /dev/index.php [L]
RewriteCond $1 !^(index\.php|images|css|js|robots\.txt|favicon\.ico|zip\.php|resources)
RewriteRule ^(.*)$ /dev/index.php?/$1 [L]
dev should be changed to the name of your subdirectory. also, if neither or these works and you have a htaccess on your root, it could be effecting this subdirectory.
This is now sorted after a lot of different attempts!
File config.php in root -> application -> config (line 46) was originally:
$config['uri_protocol'] = ($_SERVER['SERVER_ADDR'] == '127.0.0.1') ? 'AUTO' : 'ORIG_PATH_INFO';
It should be:
$config['uri_protocol'] = ($_SERVER['SERVER_ADDR'] == '127.0.0.1') ? 'AUTO' : 'PATH_INFO';
All's now functioning correctly.
I want to load my new website from subdirectory including default index.html page.
In my public_html, I have /oldsite/ and /newsite/ folders...
Then.. When I access to http://www.mysite.com/.. i want it to load all contents from http://www.mysite.com/newsite/ without redirecting. I want to do it with .htaccess mod_rewrite if possible..
Can anybody help me out with this. How to do this?
# to ensure that server already know that you going to use mod-rewrite
RewriteEngine on
# if the request from http is mysite.com or www.mysite.com go to next line (else abort)
RewriteCond %{HTTP_HOST} ^(www.)?mysite.com$ [NC]
# if the request destination is not the folder /newsite go to next line
RewriteCond %{REQUEST_URI} !^/newsite/
# if the requested name is not an existed file in public_html directory
RewriteCond %{REQUEST_FILENAME} !-f
# if the requested name is not an existed directory in public_html directory
RewriteCond %{REQUEST_FILENAME} !-d
# forward request to /newsite/
RewriteRule ^(.*)$ /newsite/$1
# if the request domain is mysite.com (with out any string afterward), go to next line
RewriteCond %{HTTP_HOST} ^(www.)?mysite.com$ [NC]
# forward request to the default file under newsite directory
RewriteRule ^(/)?$ newsite/ [L]
It is generally not a good idea to deploy a website like this. Instead you should create virtual hosts for the live and development versions of your site. If you can't do that with your current hosting provider you can make use of symlink for public_html and when the new version is ready to go live just change its path. Hope that helps.
I have the following lines in the .htaccess file in the site directory:
RewriteEngine On
RewriteRule ^([a-z]{1}[a-z0-9_-]{3,20})$ account.php?username=$1&%{QUERY_STRING}
If it receives URL for example :
http://localhost/samplesite/johnsmith
it will rewrite it to
http://localhost/samplesite/account.php?username=johnsmith
which is fine.
The problem occurs when there is a directory named johnsmith in the site directory. then the URL is rewritten to and displayed as
http://localhost/samplesite/johnsmith/?username=johnsmith
and that is a problem. I am trying to implement account pages functionality for every user but if a user wants to register a username like some directory in the root the functionality will break? I tried adding rewrite conditions to check if the requested URL stands for an existing directory or a file :
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
but I don't know how to proceed.
If someone knows a better way to do account pages functionality for users I would appreciate to give me a piece of advice on that.
Can anybody help me solve this case? Thank you!
Your RewriteCond will work if it is in the correct place. Your full .htaccess should look like:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
# ---------------------------------------------------------------See info below--
RewriteRule ^([a-z]{1}[a-z0-9_-]{3,20})$ account.php?username=$1&%{QUERY_STRING}
Also, you don't need the %{QUERY_STRING}. Instead you should use the QSA flag to append the rest of the query string...
RewriteRule ^([a-z]{1}[a-z0-9_-]{3,20})$ account.php?username=$1 [L,QSA]
I have a little problem with my apache2 and .htaccess rules.
for example:
I have a shortened uri like
www.domain.tld/sitemap
which has to be rewritten by a rewriterule, redirected in a php File to display the sitemap.
The problem is, that in the root folder a file named sitemap.xml exists.
My apache automatically calls the sitemap.xml file but i don`t want that.
The file should be only called when uri is
www.domain.tld/sitemap.xml
is there a possibility to avoid the call of this file when the shortened URI is called?
this is just an example. There are some files that are required to be in the root folder and can`t moved from there into a subfolder (which would be the easiest way to fix this problem, but its not possible in my situation). it is required that these files are callable by uri.
Has anyone an idea how to fix this problem?
my current .htaccess file
RewriteCond %{REQUEST_URI} ^(.*)$
RewriteCond %{REQUEST_FILENAME} !index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ /index.php?urlseg=%1&%{QUERY_STRING} [NC,L]
Thanks a lot!
You likely have MultiViews enabled, which auto-resolves your non-existent resource /sitemap to the existent resource /sitemap.xml. Especially in cases where you're using mod_rewrite, I really see no need for MultiViews, so you can turn it off by adding this to the top of your .htaccess file:
Options -MultiViews
Doing so should hopefully prevent this from happening.