Are all requests handled in index.php?
Yes. All* requests will go through index.php there is a rewrite rule in the .htaccess file which masks this and gives user friendly urls.
# Rewrite URLs of the form 'x' to the form 'index.php?q=x'.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
If Drupal can't invoke these rules then you will see index.php in the browser URL.
**There are cron.php and update.php which don't but these are special files for admin so are not part of the run of the mill site.*
Yes. If you're looking for certain code snippets that handles URL parsing and calls various modules then take a look inside bootstrap.inc
Related
The overall goal is to create a twitter-like site where if you try to go to any of the pages that are not indicated, you will be taken to a profile page instead. While this is somewhat simple in most cases it becomes a bit more complicated inside of Joomla due to the fact that the !-f command is a bit useless. Article titles don't actually exist so this one does not.
The only alternative that I have functioning is to list every page I don't want to redirect as a condition. The result is something like this. The Custom redirects is the section in question.
# Use PHP5.3 as default
AddHandler application/x-httpd-php53 .php
RewriteEngine on
#Options +FollowSymLinks
Options +SymLinksIfOwnerMatch
## Mod_rewrite in use.
## Begin - Rewrite rules to block out some common exploits.
# If you experience problems on your site block out the operations listed below
# This attempts to block the most common type of exploit `attempts` to Joomla!
#
# Block out any script trying to base64_encode data within the URL.
RewriteCond %{QUERY_STRING} base64_encode[^(]*\([^)]*\) [OR]
# Block out any script that includes a <script> tag in URL.
RewriteCond %{QUERY_STRING} (<|%3C)([^s]*s)+cript.*(>|%3E) [NC,OR]
# Block out any script trying to set a PHP GLOBALS variable via URL.
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
# Block out any script trying to modify a _REQUEST variable via URL.
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
# Return 403 Forbidden header and show the content of the root homepage
RewriteRule .* index.php [F]
#
## End - Rewrite rules to block out some common exploits.
## Begin - Custom redirects
#
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !how-it-works
RewriteCond %{REQUEST_FILENAME} !plans-and-pricing
RewriteCond %{REQUEST_FILENAME} !contact-us
RewriteCond %{REQUEST_FILENAME} !login
RewriteRule ^(.*)$ ./index.php?option=com_profiles&view=publica&Name=$1 [R=301]
## End - Custom redirects
## Begin - Joomla! core SEF Section.
#
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
#
# If the requested path and file is not /index.php and the request
# has not already been internally rewritten to the index.php script
RewriteCond %{REQUEST_URI} !^/index\.php
# and the request is for something within the component folder,
# or for the site root, or for an extensionless URL, or the
# requested URL ends with one of the listed extensions
RewriteCond %{REQUEST_URI} /component/|(/[^.]*|\.(php|html?|feed|pdf|vcf|raw))$ [NC]
# and the requested path and file doesn't directly match a physical file
RewriteCond %{REQUEST_FILENAME} !-f
# and the requested path and file doesn't directly match a physical folder
RewriteCond %{REQUEST_FILENAME} !-d
# internally rewrite the request to the index.php script
RewriteRule .* index.php [L]
#
## End - Joomla! core SEF Section.
Now this works perfectly with one minor hitch. It appears that the css for this page is actually using the referring page's. Joomla is made modularly so the template calls for a content section and the content section is being replaced while the rest is not. This includes header files linking to style sheets.
I was hoping some of the people here might be able to take a look at this and tell me what is preventing this from being a proper redirect. I don't really use htacess so some of the nuances are lost on me.
I recently switched over my website to Wordpress. My old files were www.example.com/about.php and now its www.example.com/about/. I need to redirect incoming links from the .php extension to just the / for ALL my pages preferably using .htaccess.
What I have:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php [NC,L]
Whats in my .htaccess file:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
I guess I don't know where I'd put it in my .htaccess file either.
Thanks!
The code you have does not redirect anything. It takes a request that might be for a php file and internally appends the .php extension. Nothing happens on the browser because you've not told it to do anything. This is a 2 step process here. See the top part of this answer for a short explanation.
In order to redirect, you need to match against the incoming request, not the URI (which could have been rewritten be previous rules or iterations):
RewriteCond %{THE_REQUEST} ^(GET|HEAD|POST)\ /(.*)\.php($|\ )
RewriteCond %{REQUEST_URI} !wp-admin
RewriteRule ^ /%2/ [L,R=301]
So when someone types http://www.example.com/about.php in their browser's URL address bar, the request will look like:
GET /about.php HTTP/1.1
and the %2 backreferences about and redirects the browser to http://www.example.com/about/ (note the trailing slash) and the address bar changes.
What happens then is the browser makes ANOTHER request but this time for http://www.example.com/about/ and the server gets the URI /about/. Now you need your rule to internally rewrite it back to the php file. Unfortunately, your rule doesn't handle the trailing slash, so you need something like this:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^/(.*?)/?$
RewriteCond %{DOCUMENT_ROOT}/%1.php -f
RewriteRule ^ /%1.php [L]
These would all go before your wordpress rules. The wordpress rules route everything to index.php and that would wreck any URI you are trying to rewrite.
You are doing things the wrong way around. You are actually rewriting urls that end end without php to files that do end in .php.
You'd need to do something like this:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*).php$ $1/ [NC]
I also removed the check if the file you are redirecting to exists as well as the [L] flag, because it's likely that wordpress is also doing its own rewriting, which means that you don't want this to be the last rule processed and that you won't be able to find the file on the filesystem.
i have a wordpress site that currently shows the posts like
http://mysite.com/index.php?p=1
and now i wanna access the same thing by writing url as
http://mysite.com/1
what can be the rewrite rules to do that.. i saw the .htaccess that hides the index.php from the url and regular expressions but was not being able to properly do what is needed!
In the htaccess file in your document root, preferably before any wordpress related rewrite rules, add these:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/?([0-9]+)$ /index.php?p=$1 [L,QSA]
I'm hoping non-IIS people can help me on this though the issue I'm having is based around an IIS6 server running ISAPI_Rewriter.
The situation is that I'm running Wordpress on IIS6, ISAPI_Rewriter is being used to act as a replacement for mod_rewrite and is functioning properly. My problem is that when I get it to rewrite my URLs for Wordpress (so I don't need the index.php filename in it) it shows a 404. After much searching I found the problem was because part of the ASP.net (or something similar) was adding eurl.axd/[random string] to the end of the URLs and so this was being fed into the Wordpress request and breaking it. I set the Wordpress template to output the requested URL and it looks something like this:
http://www.example.com/index.php/about/eurl.axd/b552863f2d5e9841b5d8b79b44ac02e8/
I believe this is because of the pecking order of various things in the IIS system and the culprit is required to run another part of the project. I'd prefer to keep using ISAPI_Rewriter to pretty up the URLs so I'd like to know this:
Is there any way of getting mod_rewrite to remove eurl.axd/[string] before feeding it on to the system?
My .htaccess file currently appears as such:
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# The following line excludes folders from rewriting
RewriteCond %{REQUEST_URI} !^/folder-name/
RewriteRule ^/(.*)$ /$1 [NC,L]
Thanks for all the help, it is always greatly appreciated.
EDIT: Have adjusted my htaccess based on suggestions and it seems to work well from the brief tests I have carried out. Have posted it below.
RewriteEngine on
RewriteBase /
# This is used to strip ASP.net eurl.axd bits
# from the URL so wordpress can use permalinks
# For the root
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/wp-admin/
RewriteRule ^eurl\.axd/[0-9a-f]+/$ index.php [NC,L]
# For internal permalinks
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/wp-admin/
RewriteRule ^(.*)/eurl\.axd/[0-9a-f]+/$ index.php/$1 [NC,L]
Something like this near the top of your list of rewrites should work:
RewriteRule ^(.*)/eurl\.axd/[0-9a-f]+/$ /$1
I use the following regex as first rule with Ionics Isapi Rewriter for web sites running on ASP.NET 4 on IIS 6 to remedy the problems caused by the breaking change introduced with ASP.NET 4 :
RewriteRule ^(.*)/eurl.axd/[a-f0-9]{32}(.*)$ $1$2
This let me again use extensionless urls.
Note that the second group captures the querystring if present and restitutes it to the rewritten url.
And yes, it's a feature, not a bug.
I ran into a similar issue with v4.0 ASP.Net extension less URL feature on II6 and found a solution through ISAPI Rewrite Module provider, the does not require turning it off. Theissue and the solution as we experienced it is documented here http://www.vanadiumtech.com/OurBlog/post/2011/08/12/Cause-of-eurlaxd.aspx
I'm using Wordpress and have the following pemalink /%category%/%postname%.
This gives me user friendly URLs like http://www.example.com/something/.
With this permalink, I will not be able to access php files directly, e.g. http://www.example.com/something/myfile.php.
I need to write a ReWrite rule which allows me access to /include/myfile.php.
Can some help me please? :)
Here's my current .htaccess file:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /myblogdirectory/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /myblogdirectory/index.php [L]
</IfModule>
# END WordPress
Update
Ok, I got it working.
I was doing it wrong from the start. I was using the "virtual" path instead of the physical path.
Instead of /mysite/includes/myfile.php, I have to use /wp-content/themes/mytheme/include/myfile.php
I could probably also have added RewriteCond %{REQUEST_URI} !myfile.php, which would have excluded myfile.php from the rewrite rules. I have not tested this though.
Well, your rewrite rules looks good.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
means that /blog/index.php won't be serverd if %{REQUEST_FILENAME] is a physical file or directory.
More info here.
Are you sure that you're using the correct file paths?
The file you want to request should be located in /blog/include/myfile.php.
Check your error.log for apache for any related messages.