I changed the path in Drupal for a number of nodes and I need any external links that reference the old path to redirect to the new path. I don't know if path is the right word since everything is directed at index.php For example, the old ones were reached at http://domain.com/thepress/node/1111. In Drupal they've been changed to http://domain.com/thenews/node/1111. I need to redirect to the new uri any external urls that request those "pages" My .htaccess:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^thepress/([^.]+) thenews/$1
RewriteRule ^ index.php [L]
Any help is appreciated. I want to just strip the substring /thepress/ and replace it with /thenews/ and pass that to index.php for drupal to pull up the correct pages.
You need to redirect old URL to new one using R flag. Try these rules:
RewriteRule ^thepress/([^.]+)$ thenews/$1 [L,NC,R=302]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^ index.php [L]
Related
I'm trying to do a rewrite, where if the page doesnt exist, it rewrites to a category page. Its a bit different to the normal RewriteCond %{REQUEST_FILENAME} -f as the page name is dynamic based on the URL.
If somebody visits a dynamic path name such as "/contacts"
I first want it to check if the following folder/file exists based on the path name:
/[dynamicpath]/[dynamicpath].php
example:
/contacts/contacts.php
If that doesnt exist, rewrite to the following page
/categories/category/category.php?cat_url=[dynamicpath]
example:
/categories/category/category.php?cat_url=contacts
I've tried the below, but it fails with the first RewriteRule triggering when the file exists and goes straight to the category rewrite.
RewriteCond %{SCRIPT_URL} ^(.+)
RewriteCond %{DOCUMENT_ROOT}/%1/%1.php !-f
RewriteRule (.+)/?$ $1/$1.php [QSA,L]
RewriteRule ^([\w-]+)/?$ /categories/category/category.php?cat_url=$1 [QSA,L]
You may use these rules in your site root .htaccess:
RewriteEngine On
# attempt rewrite to /[dynamicpath]/[dynamicpath].php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1/$1.php -f
RewriteRule ^(.+?)/?$ $1/$1.php [L]
# else rewrite to categories/category/category.php?cat_url=...
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+?)/?$ categories/category/category.php?cat_url=$1 [QSA,L]
I found the answer by checking the server variables being passed and discovered %{REQUEST_FILENAME} included the full file path (document_root+filename).
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI}%{REQUEST_URI}.php -f
RewriteRule ^(.+)/?$ $1/$1.php [L]
RewriteRule ^(.+)/?$ categories/category/category.php?cat_url=%{REQUEST_URI} [QSA,L]
Hello guys can you help me how set proper url in codeigniter using multiple applications and i proper .htaccess
Folder Structure
-application
-api
-cms
-system
-api.php
-cms.php
Its works when a use this
http://localhost/kitkat_funs/cms.php/
http://localhost/kitkat_funs/api.php/
But i want this
http://localhost/kitkat_funs/cms/
http://localhost/kitkat_funs/api/
My htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
Please try following steps:
In config=>config.php, replace like following.
$config['index_page'] = 'index.php';
to
$config['index_page'] = '';
Please put following code into your .htaccess file, this might help you to achieve the result.
write your project folder name as rewritebase
RewriteBase /yourprojname/
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/system.*
RewriteRule ^(.*) index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+) index.php?/$1 [L]
*take backup of your .htaccess file.
This problem appear when you working with Codeigniter using Multiple application(and multiple index_appname.php. Ofcourse you can add new line in .htaccess everytime you add another application but that is not convenience.
The solution is using basic Regular Expression. You need to write 2 section, one is for address without slash, and the other with more than one slash after index file
Note: in this case the index.php file has prefix "index_" following with app name
# If the user types without trailing slash example www.host.com/kitkat_funs/appname
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(\w*)$ index_$1\.php [L,QSA]
# If the user enter in any system section with slash example www.host.com/kitkat_funs/appname/page/etc
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\/(.*)$ index_$2\.php/$1 [L,QSA]
Everytime user enter address right after domain name, for example www.host.com/kitkatname/cms
.htaccess will automatically redirect to www.host.com/kitkatname/cms.php
now you can get rid .php extension on your index file
We have a client, where were building a new site. There old system had all articles under:
http://www.domain.com/articles
The new site is
http://www.domain.com/resources/articles
Within the articles section url can be as long as:
http://www.domain.com/resources/articles/category-name/title-of-article
and there is
http://www.domain.com/resources/articles/page/# for the pagination
The new site will have the same url structure of the old articles except for the /resources part.
I need to have all incoming traffic that comes under:
http://www.domain.com/articles redirected to http://www.domain.com/resources/articles however I need to make sure that the category name and the title of the article in the url string are also placed in from the old string that was requested to the new one.
How can I do this using htaccess?
--- EDIT ---
Here is my current htaccess:
RewriteEngine on
RewriteRule (.*) $1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/(.*)/(.*)$ ?cat=$1&title=$2&subtitle=$3 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/(.*)$ ?cat=$1&title=$2 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) ?cat=$1
On your old site:
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
RewriteBase /
RewriteRule ^(articles/.*)$ /resources/$1 [L,R=301,NC]
Im working on a server with the following htaccess:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule .* index.php
RewriteRule ^[^/]*\.html$ index.php
RewriteRule ^/(typo3|typo3temp|typo3conf|t3lib|tslib|fileadmin|uploads|showpic\.php)/ - [L]
RewriteRule ^/(typo3|typo3temp|typo3conf|t3lib|tslib|fileadmin|uploads|showpic\.php)/.*$ - [L]
Now they asked me to prepare a static page inside their server, lets call it http://www.myserver.com/mystaticpage.html
The problem is that when i try to access that url, it redirects to index.php. How could I alter the htacces file to address this problem without messing anything with the installed CMS?
Try this:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond ${REQUEST_URI} !^/(typo3|typo3temp|typo3conf|t3lib|tslib|fileadmin|uploads|showpic\.php)
RewriteRule .* index.php
The rules you used before were redundant: if .* is rewritten to index.php then why also rewrite ^[^/]*\.html$ index.php to it? it already matched previous rule...
They also overlapped - since the three RewriteCond conditions were only applied on the first rule. So the second rule was also applied to static files on disk.
Also, the two rules that were listed last had no effect whatsoever. Either you needed to list them first, or not at all. I converted them to an additional RewriteCond since they were only attempted to avoid rewrite on certain uris
i want to change a url like : localhost/site/home.php?p=index to localhost/site/index
i use this code in my htaccess file
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/?$ home.php?p=$1 [L,NS]
but when i write like localhost/site/home.php?p=profile.user i get the 404 error, and go to this link
localhost/profile.user
so how can i fix itthanks
Let's look at your rewrites first:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/?$ home.php?p=$1 [L,NS]
This is relative rewrite: the replacement text home.php... does not begin with a slash. Relative rewrites in a per-directory context (<Directory> or .htaccess) require a RewriteBase directive to be configured, otherwise they do the wrong thing.
Secondly, your rule is backwards, If you want to rewrite the home.php URL to the site/index one, you have to put the home.php match on the left side, and the site/index on the right:
RewriteRule ^home.php?p=(.*) /site/$1
Notice that I have an absolute rewrite. This means that mod_rewrite will create a URL out of the rewrite by sticking http://example.com on it. A new request is internally generated now for http://example.com/site/<whatever>. We can get away without using RewriteBase since we have no relative rewrites.
As for your last question, it is not clear why when you access localhost/site/home.php?p=profile.user you're being taken to localhost/profile.user. I'm suspecting that it's your home.php script doing that, perhaps. You're trying to use mod_rewrite to hijack that particular kind of PHP request and send it elsewhere, right?
What you meant is probably: you want to rewrite this way:
http://mysite.com/index => http://mysite.com/home.php?p=index
So this should work
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/?$ /home.php?p=$1 [QSA,L]
Now if you want the opposite:
http://mysite.com/home.php?p=index => http://mysite.com/index
This should work:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule /home\.php$ / [QSA,L]