htaccess redirect wordpress to index2.php - php

We have a site running on WordPress ada.localhost.com
Now all request to base url (http://ada.localhost.com/) have to go through tracking page (track.com/c/0912321323/?u=xxx) where u parameter is where to redirect user after he is tracked.
I've created a copy of index.php (index2.php) and I want to create htaccess rule to redirect all base url traffic to:
http://track.com/c/0912321323?u=http%3A%2F%2Fada.localhost.com%2Findex2.html (http://ada.localhost.com/index2.php)
Typical WP htaccess file looks like this
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Any clue on how to set it up and if WordPress allow this configuration?

From what I found WordPress won't work with index2.php.
Solution for this is to write a plugin which deals with it.

Related

htaccess rewrite rule to Wordpress page without changing URL

I have a rewrite rule in my .htaccess file:
(/.htaccess)
RewriteBase /
RewriteEngine On
RewriteRule ^wptest$ ./wp/main/ [L,R]
I've tried lots of combinations of different switches here, no R, P, OR etc, most caused problems.
The Wordpress htaccess file is untouched:
(/wp/.htaccess)
RewriteEngine On
RewriteBase /wp/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wp/index.php [L]
When I enter:
{domain}/wptest
The browser resolves to:
{domain}/wp/main
but always changes the URL to: /wp/main.
The file structure is:
/.htaccess
/wp/.htaccess
(there is no file or directory /wp/main - this is the Wordpress page stub)
How can I prevent the Wordpress htaccess from changing the URL - ie going to the Wordpress page "main", but leaving the URL as /wptest?

Rewrite rule in wordpress for wordpress page

I'm running wordpress in my local with "ben.scbw.zec.dev" vhost.
I have created page template to display particular event detail.
http://ben.scbw.zec.dev/event-view?view_event=14
I can access page with above url "event-view" is slug on page and page id = 439 .
Now, I desire to access it with below url.
http://ben.scbw.zec.dev/event-view/this-is-test-event/14/
"this-is-test-event" its fro titel of event any text , i have manage to create URl.
Below is code from my .htaccess
# 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
Above is Standard wordpress crated code and i have added following code.
RewriteEngine On
RewriteBase /
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^event-view/([^/]*)/([^/]*)/$ ./index.php?page_id=439&titel=$1&view_event=$2 [L]
here 439 is in page id for "even-view" as i mentioned.
But, I'm not able to access page with "http://ben.scbw.zec.dev/event-view/this-is-test-event/14/" url. it shows me 404 not found error.
I have been trying this for 4-5 day but not able to find solution.
I'm really very Thank full if anyone can help me in this.
First of all, wordpress uses internal RewriteRules to map an url.
So you don't have to add an additional RewriteRule-tag to your htaccess.
You have to register your query parameter and add rewrite rules to the internal wordpress rewrite engine.
#see https://developer.wordpress.org/reference/classes/wp/add_query_var/
#see https://developer.wordpress.org/reference/classes/wp_rewrite/

.htaccess redirect subdomain to ssl site

I want to let my site http://subdomain.domain.com redirect to another external SSL-encrypted domain https://subdomain.external.com, while keeping the original address in the browsing bar. As far as I know, it is possible with CNAME to do this very easily, but the problem is that it redirects to the external link without SSL encryption.
I have been told that this can be done with .htaccess file, which right now has the following contents:
# 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
Can you help me know how should I modify the .htaccess file to meet my requirement? Thank you very much!
Juan
If you want to do it with PHP:
$redirect = "https://www.ssl.com".$_SERVER['REQUEST_URI'];
header("Location: $redirect");
exit;
Then you have to route all requests to this PHP file via .htaccess:
RewriteEngine on
RewriteRule ^([^.]+)$ index.php [QSA]

URL redirection in Wordpress manually by editing .htaccess file

please help me to fix my one of wordpress problem with URL redirecting in PHP.
This is my original wordpress htaccess file.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
I want to create custom URL redirection here. For ex.,
I want to redirect pages,
http://example.com/b/1 > http://example.com/b?n=1
http://example.com/b/2 > http://example.com/b?n=2
i am using directory URL type (displaying URLs as directories without extensions) SEO options in wordpress settings.
inside of http://example.com/b page, I have included another php file using ‘include(‘z.php’);’ command.
Z.php is reading URL parameter comes from ‘/?n=1’ through redirected URL.
I tried below solution, but no luck..
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^b/([^/]*)$ /b/?n=$1
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Appreciate any of help.
EDIT
wordpress header file can read the translated parameters. i checked that by displaying GET parameter 'n' in title.
but it shows file not found for http://example.com/b/
i verified that, by editing http://example.com/b/ page content. non of page content displaying after rewriting.
Any help appreciated
EDIT
URL may have characters in parameter as below.
http://example.com/b/abc_1 > http://example.com/b?n=abc_1
http://example.com/b/aa_2 > http://example.com/b?n=aa_2
Thanks for Helping
At first sight it seems to me that it should be
RewriteRule ^b/([^/]*)$ /?p=$1
Wordpress doesn't know what to do with the url /b?n=X.
If you want http://example.com/b/abc_1 to work, the abc_1 part must match the slug of a wordpress post.
Additionally you have to change the settings->permalink structure to match either postname or a custom structure like /b/%postname%.
http://example.com/b/1
to
http://example.com/b?n=1
Using this
RewriteRule ^b/([0-9]+)/?$ b?n=$1 [NC,L]
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^b/([0-9]+)/?$ b?n=$1 [NC,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Test hear
More info
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^b/([^/]*)$ /b/?n=$1
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
#add below line
RewriteRule ^b/([0-9]+)/$ http://example.com/b?n=$1 [L]
</IfModule>
I found the word press related solution for this question.
in word press all the requests are heading to index.php automatically. if we create custom rewrite to another page, that request not going through index.php. that makes wordpress unidentified request and wordpress will return page not found message.
becasue of that, we have to redirect custom rewrite to index.php instead of permalink.
i used
RewriteRule ^b/([^/]*)$ index.php?page_id=4&n=$1
this rule redirected all requests matched with rule to index page. (my page ID for /b/ is 4)
this worked successfully for me.
other solutions above worked for non wordpress situations. but i found wordpress behavior as i explained.
appreciates who tried to answer.

Website redirection problems

I have been working on a website that is primarily PHP based. When a user visits the site stuff like http://robroscoe.ca/index.php, is redirected to http://robroscoe.ca and I am okay with this. What I am not okay with is, my webpages like robroscoe.ca/cv.php when you type in robroscoe.ca/cv redirecting back to robroscoe.ca. I am not sure how this happened and I am wondering if someone could explain to me what is going on.
# 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 think the .htaccess file has something to do with this but I am not sure how to modify this as Wordpress seems to have created this for me without me knowing it. Any help or reading materials would be appreciated.
Thanks for your time!
You problem is that you've created a PHP script that is separate from WordPress and are trying to access it through a 'pretty' URL which WordPress handles. WordPress does not know of a page called 'cv', and handles it like any other 404.
I would strongly recommend that you create the page within WP so it can manage its own 'pretty URL' structure.
If you're hellbent on shoehorning your own scripts in, then get cozy with hand-editing your .htaccess file for each one.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^cv/?$ cv.php [L] #new rule
RewriteRule ^index\.php$ - [L] #this is made redundant by the very next line.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

Categories